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.