WASHINGTON — In one of the most stunning primary election upsets in congressional history, the House majority leader, Representative Eric Cantor, was soundly defeated on Tuesday in Virginia by a Tea Party-backed economics professor who had hammered him for being insufficiently conservative.
Cantor’s defeat jolted the Republican Party — he had widely been considered the top candidate to succeed Speaker John A. Boehner one day — and it has the potential both to change the debate in Washington on immigration and to reshape the midterm elections, which had been favoring his party.
With just more than $200,000, David Brat — a professor at Randolph-Macon College in Ashland — toppled Cantor, repeatedly criticizing him for being soft on immigration and contending that he supported what critics call amnesty for immigrants in the country illegally. Brat will face Jack Trammell, a Democrat who is also a professor at Randolph-Macon, this fall in the heavily Republican district.
‘‘This is a miracle from God that just happened,’’ exulted Brat as his victory became clear.
With 100 percent of the precincts reporting, Brat had 56 percent of the votes to Cantor’s 44 percent.
The outcome may mark the end of Cantor’s political career, and aides did not respond Tuesday night when asked if the majority leader, 51, would run a write-in campaign in the fall.
Speaking to downcast supporters, Cantor conceded, ‘‘Obviously, we came up short.’’
Republicans were so sure that Cantor would win that most party leaders had been watching for how broad his victory would be. His defeat will reverberate in the capital and could have major implications for any chance of an immigration overhaul.
“I’m in shock,” said Representative Patrick T. McHenry, Republican of North Carolina, expressing the mood on Capitol Hill.
Democrats seized on the upset as evidence that their fight for House control this fall is far from over.
‘‘Eric Cantor has long been the face of House Republicans’ extreme policies, debilitating dysfunction, and manufactured crises. Tonight is a major victory for the Tea Party as they yet again pull the Republican Party further to the radical right,’’ said the Democratic leader, Nancy Pelosi of California.
Cantor, who is in his seventh term, had sought to rebut Brat’s charges on immigration, using some of his $5.4 million to send fliers and air television ads in which he claimed to oppose an “amnesty” policy. But with significant help from conservative talk radio figures such as Laura Ingraham, Brat was able to galvanize opposition to Cantor in one of Virginia’s most conservative congressional districts.
Ingraham, one of the few high-profile conservatives to put her muscle behind Brat, said on Fox News on Tuesday night that the primary results were “an absolute repudiation of establishment politics” and that Republican leaders should take note.
“I think there will be a lot of people out there saying this could be the beginning of something really big for the Republican Party,” she said.
Cantor’s loss recalled the defeat of former speaker Thomas S. Foley, a Democrat who lost to a little-known Republican, George Nethercutt, in the 1994 general elections that delivered control of Congress to the Republicans. It is extremely rare for a member of the congressional leadership to lose a primary.
Cantor had won primary elections in his district around Richmond — which stretches more than 100 miles from the Tidewater region nearly to the Washington suburbs — with as much as 79 percent of the vote.
Within the Republican Party, he was seen as a star, with the ability to tap into the energy of the House’s more conservative members while at the same time not alienating the party’s establishment wing.
In the House, his relationship with Boehner reflected some of the larger tensions within the party. Cantor strongly opposed, for instance, negotiations between the speaker and President Obama that could have restructured entitlement programs and the deficit.
Cantor received what amounted to a warning shot from local Republicans at a district convention last month in Henrico County, his political home base, when conservatives ousted one of his loyalists as Republican chairman while he looked on.
The majority leader also faced anger for the perception that he was too detached from his district.
Cantor, who began his career as the youthful driver to his predecessor, Representative Thomas J. Bliley Jr., had a longstanding ambition to become speaker of the House.
Reaching that pinnacle had, of late, seemed as close as ever, with Washington full of speculation that Boehner would soon retire.
Cantor was part of the team that led the GOP to victory in 2010 and the mastermind of a program that propelled the very sort of Tea Party candidate who ultimately spelled his doom.