RICHMOND, Ky. — Representative Andy Barr, an incumbent Republican, defeated one of the Democratic Party’s most prominent challengers, Amy McGrath, on Tuesday in a deeply conservative district here, according to The Associated Press, giving his party hope of limiting losses in the race for control of the House.
The contest took on national importance as a proxy for whether Democrats could win over white working class voters in rural areas and whether women would rise up against the barbed-wire rhetoric and harsh policies of the Trump presidency.
It was among about 30 tossup districts, including many, like Mr. Barr’s, where Republicans held a distinct partisan advantage. Public polling seesawed between a Republican lead and a Democratic lead, ending this week in an exact tie. Mr. Barr’s victory on Tuesday signaled that Republican-controlled districts were still asserting their allegiance to the president, and may have been swayed by the issue of immigration and the Supreme Court nomination fight over Justice Brett M. Kavanaugh.
Mr. Barr tethered himself closely to the president and to the Senate majority leader, Mitch McConnell of Kentucky, as he cast Ms. McGrath as an unreconstructed liberal in the mold of Representative Nancy Pelosi of California, who was for open borders and abortions as late as the ninth month of pregnancy.
He was aided by millions of dollars of spending on attack ads against Ms. McGrath funded by the Congressional Leadership Fund, the super PAC supported by Speaker Paul D. Ryan whose largest contributor is the casino magnate Sheldon Adelson. Ms. McGrath refused to respond with her own attack ads, instead choosing to mock Mr. Barr, often with the tagline, “Is that all you got?”
Mr. Barr is well known in the district for attending all manner of local festivals and delivering on legislation that affects the area. But he found himself on the defensive over tariffs imposed by Mr. Trump that hurt the local bourbon and automotive industries along with soybean farmers.
In the closing weeks of the campaign, he returned to themes that echoed the ones that Mr. Trump was emphasizing.
The president had put his personal popularity on the line in the race, recently coming to campaign for Mr. Barr one day after former Vice President Joseph R. Biden Jr. came to Owingsville, Ky., a rural part of the district to support Ms. McGrath and to emphasize his party’s need to reconnect with the white working class.
In Ms. McGrath, whose biography as a Marine aviator gave her star power and a huge fund-raising advantage, Mr. Barr found himself running against a résumé that he could not match. So he emphasized his conservative ideology, and prevailed.
The district is anchored in Lexington, its most populous city by far and typically a Democratic stronghold, and the state capital of Frankfurt, another source of Democratic votes. But those cities are surrounded by mostly rural counties that are ardently conservative. In 2016, Mr. Trump won the district by 15 percentage points and Mr. Barr won by 22 points.
Ms. McGrath’s campaign opened campaign offices in all 19 counties, and she aggressively targeted rural areas, with yard signs tailored to individual counties, some even in Republican red, and by writing op-eds that her campaign placed in weekly newspapers.
That strategy served her well in her primary campaign against Jim Gray, the popular mayor of Lexington, who was better known and had stronger financial backing. But she defeated Mr. Gray easily, and built on her strengths in rural areas during the fall campaign against Mr. Barr, pulling votes from people who were ancestral Democrats but vote for Republicans in federal office.
Ms. McGrath started out under financed, but her campaign money fortunes changed drastically in August 2017 when she released a two-minute video online that captured her Marine combat experience, the struggles of women and her reasons for running for office. The ad generated millions of page views and contributions, enabling her to have rough parity with Mr. Gray, and then build on an emerging national profile.
“The video catapulted her to legitimacy,” Mark Nickolas, Ms. McGrath’s campaign manager, said.
But it was not enough to overcome the power of Mr. Barr’s incumbency, a district that was structurally advantageous to Republicans and the closing moves of the president to roust his political base and make the election a referendum on him.