RICHMOND — Republican Dave Brat followed his stunning primary victory over then-House Majority Leader Eric Cantor by beating his Democratic opponent on Tuesday to win a congressional seat.

Brat defeated Jack Trammell in central Virginia's heavily Republican 7th District. Libertarian James Carr finished a distant third.

In June, Brat rode a wave of tea party support to an upset over Cantor, who was the second-ranking member of the House of Representatives. Cantor was in his seventh term and was widely considered a likely successor to House Speaker John Boehner. He resigned in August and took a job with a New York investment bank.

Voters in the district had to cast two ballots — one to fill the remainder of Cantor's unexpired term, the other for the full term beginning in January. Brat won both handily.

Brat and Trammell both teach at Randolph-Macon College in Ashland. It will be the first public office for Brat, whose only previous campaign was a failed bid for the GOP nomination for a state House of Delegates seat.

Trammell acknowledged that he faced long odds because of the district's political makeup.

"I think that's one of the key takeaways, that this district is so gerrymandered it's going to be hard for a Democrat to win here," Trammell said in a telephone interview moments after he called Brat to congratulate him. He said Brat also benefited from the national spotlight after knocking off Cantor.

The sociology professor did not rule out another run for public office.

Brat could not immediately be reached for comment.

During the general election campaign for Congress, Brat trumpeted his opposition to most of President Barack Obama's policies, including health care overhaul and less restrictive immigration rules. He also emphasized his experience as an economics professor, suggesting he would be the best choice to help rein in federal spending and improve the nation's economy. He pledged to work for "a fair and flat tax."

Trammell defended some of Obama's policies. However, he sought to overcome the president's sagging popularity in Virginia by reminding voters that Obama was not on the ballot and by portraying himself as a bipartisan consensus-builder.

Immediately after his surprising 11-percentage-points victory in the primary, Brat retreated from the public spotlight for several days.

When campaigning resumed, Trammell accused Brat of being inaccessible — the same label many of Brat's supporters had attached to Cantor. Brat countered that Trammell ran deceptive television ads against him and accused him of running a dishonest campaign.

Fred Burger, 75, said he voted for Brat both in the primary and Tuesday. He said he felt like Cantor had forgotten to serve his district.

"I don't think Brat is going to neglect his people," Burger said.