After losing his primary to tea party challenger David Brat, House Majority Leader Eric Cantor (R-Va.) announced he will be stepping down from House leadership at the end of July. (Associated Press)

Last month in Richmond, Eric Cantor stepped to a microphone in a hotel ballroom full of Republican activists from his home district. He was clearly ticked off.

Cantor’s wife and two of his kids were there. His mother was there. His mother-in-law was there. And right there in front of them all, a little-known professor from a little college had just called Cantor a bad conservative. The normally cool Cantor was about to strike back — showing a pique he has turned on the president but rarely shows in public.

“When I sit here and I listen to Mr. Brat speak,” Cantor started, referring to challenger Dave Brat, “I hear the inaccuracies . . .

The crowd cut him off. After all of 24 seconds.

Then the man who expected to inherit the House of Representatives was drowned out by a bunch of booing nobodies.

“Listen,” Cantor said, struggling to be heard. “We are about a country of free speech, so decency is also a part of this.”

Now, after Cantor’s historic defeat in the Republican primary Tuesday, an entire party is picking through the wreckage of his campaign, trying to understand what went wrong.

Some Republicans spent Wednesday working on conspiracy theories, indulging the idea that there was no way they could have seen this coming. Maybe, some said, voters secretly and suddenly turned on Cantor because he is Jewish? Or maybe it was the “Cooter Effect?” That was the theory that Cantor lost because Democrats came out to vote against him — following a plan laid out in an “open letter” from an obscure ex-congressman, Ben Jones, who played Cooter the mechanic on “The Dukes of Hazzard.” (Jones had served as a Democrat from Georgia before moving to Virginia and running unsuccessfully against Cantor in 2002.)

The answers to those questions are likely no, and no.

Instead, a look back at Cantor’s defeat shows that it was a real rejection by a broad swath of his district’s Republican voters. And there were warning signs that it was coming: the heckling of Cantor in that convention speech and defeats of his acolytes in low-level party elections this year.

But Cantor missed those signs for far too long — focusing on his ambition in the House while his base crumbled beneath him.

Then, when he realized there was some danger, he reacted clumsily: launching an ad blitz that was supposed to destroy his opponent but actually left him looking like a legitimate alternative. In the confrontational GOP culture that Cantor had helped create, the highest measure of a conservative was that powerful interests wanted to destroy him. Now, Cantor was signaling, here was such a man.

“They really created their own nightmare in a lot of ways. But Eric Cantor has been creating his own nightmare for years,” said Jamie Radtke, co-founder of the Virginia Tea Party Federation and a Brat volunteer from Hanover County, Va.

Of Cantor, Radtke said, “He made an enemy of his friends.”

Cantor, 51, has been in Congress for more than 13 years now. But in all that time, his only close election was his first one: the 2000 Republican primary, which he won by less than one percentage point.

Since then, he had always won big. In some years, he faced no primary opponent at all.

When Virginia’s districts were redrawn in 2010, the state’s legislature altered Cantor’s district and removed some heavily Democratic precincts in the Richmond area. They swapped in heavily Republican New Kent County, east of the state capital.

Cantor supported the move, which was supposed to make his safe seat even safer from Democrats. But that was a miscalculation: Cantor had misjudged where his real threat would come from.

A threat to Cantor was already growing within his own party, in which some tea party members had begun to conclude that he was not conservative enough for them. In 2010, Cantor seemed to affirm that impression, skipping the state’s first tea party “convention,” where attendees cheered lustily for his opponent.

In Tuesday’s primary, the same forces unseated him — the more Republicans who showed up, the worse off it was. Those new voters from New Kent County turned sharply on Cantor, and he performed worse there than in all but one of the counties he represents.

“Ironically, New Kent was given to Cantor in redistricting to help him out. Instead, it backfired,” said Michael McDonald, a political science professor at George Mason University.

When this election began, it looked like a mismatch. No majority leader, from either party, had ever been defeated in a primary. Cantor seemed unlikely to be the first: He raised more than $5 million, and outside groups also spent hundreds of thousands of dollars on Cantor’s behalf.

Brat, 49, an economist at Randolph-Macon College in Ashland, Va., had never held elective office before. He had little money — he raised about $200,000 — and little backing even from tea party groups.

“I mean, it’s a miracle,” Brat told Fox News’s Sean Hannity on Tuesday night, seemingly stunned at the victory himself. “First of all, I attribute it to God.”

But Brat was not as helpless as he first seemed. He had key allies on conservative talk radio, like hosts Laura Ingraham and Mark Levin. They talked him up to listeners, giving Brat a free way into Virginians’ homes and cars. Ingraham also campaigned for Brat in person, holding a huge event on June 3 at a tennis and golf club not far from Cantor’s own home outside Richmond.

Inside, the two-story atrium and balcony were so packed that Don Blake, chairman and president of the Virginia Christian Alliance, said he struggled to document the evening.

“It was so crowded, you could not get a decent shot. I could see her through other people. She was great. The crowd loved her,” said Blake, who didn’t endorse a candidate before the primary. He added: “She just was so personable and down to earth. She spoke from the heart.”

“Who do you think Barack Obama and Nancy Pelosi want to win this primary?” Ingraham asked the crowd. Cantor, the crowd replied. “Why do they want Eric Cantor to win? They want Eric Cantor to win because Eric Cantor is an ally . . . [in] the fight for immigration amnesty.”

Beyond that kind of large rally, Brat’s supporters tried to set up a basic ground game, making phone calls and knocking on doors.

“Everyone assumed this race had no legs, yet we knew we had a really great candidate,” said Nancy Smith, a Brat supporter from Henrico County. “And we knew there was a lot of anti-Cantor fervor around the district.”

Smith said the volunteers found something interesting. Unlike in much of the rest of the country, the top issue for voters was not the economy, Smith explained. Life in Virginia was pretty good for most 7th District residents — the stock market was on the rise and they weren’t in financial panic mode.

But, she said, they found that many Republicans in the district were still unhappy with Cantor. He had voted to raise the debt ceiling. And he had supported a Republican version of the Dream Act, which would enable some illegal immigrants who entered the country as children to qualify for in-state college tuition rates.

“Cantor’s votes started to be the driving message,” Smith said.

As months passed, there were some worrying signs for Cantor. One of his allies lost a race for the position of district Republican chairman, despite an expensive blitz from Cantor’s campaign. Cantor’s campaign paid $3 apiece in postage to send personalized trinkets to party loyalists. And on convention day, the committee bought up all the hotel’s conference rooms to stymie Brat’s supporters. They even provided day care for the kids of their own supporters.

Cantor’s candidate got beaten. And Cantor got heckled, on the same day.

But, in the incumbent’s camp, they dismissed what turned out to be a major warning sign.

“There were 600 people there to raise Cain,” Cantor strategist Ray Allen told The Washington Post afterward. “We had 48,000 voters in the primary two years ago. It’s just a very quantum-leap different thing.”

Cantor’s team tried to reinforce its advantage with TV ads attacking Brat, calling him a liberal college professor who’d been appointed to an advisory panel by Democratic Gov. Timothy M. Kaine (Va.). Cantor spent at least $400,000 producing and airing television ads, according to federal filing reports. He began with a small buy in late April, then dramatically expanded the TV campaign in mid-May.

But the ads repeated Brat’s name again and again, alerting many voters to the fact that he existed at all — and that he seemed to threaten Cantor.

To Cantor’s people, it seemed this was working. In late May, an internal poll showed Cantor ahead of Brat by 34 points, according to Cantor aides. On Wednesday, pollster John McLaughlin said the poll was flawed — but in a way that he could not have known then.

In an interview, McLaughlin said the people polled were those who had voted in past Republican primaries. The poll did not anticipate that, on Tuesday, so many more people would show up. He suggested that many Democrats and others who haven’t voted in previous primaries came out on Tuesday.

“Polls don’t predict turnout. You’re trying to make assumptions of who usually votes,” McLaughlin said. “Here Eric got hit from the left and the right, and it created a large turnout.”

Around the district, there was a perception among some Republicans that Cantor had grown distant.

“I wouldn’t say he’s been here a lot. And the thing is, he hadn’t had too many wide-open big events,” said Bob Arment, the chair of the Republican Party in Louisa County, Va. Arment said that when Cantor did visit his district, he tended to hold “invitation-only” events, limited to people who were already known supporters or GOP bigwigs. Arment said that voters told him “they hadn’t seen [Cantor]. They’d like to see him. When’s he coming to Louisa County?”

Did that hurt Cantor in the election? “I’m sure of it,” Arment said.

In the last days before that election, Cantor’s camp began to worry that not enough of its supporters would turn out. So Cantor went out to rally his people. He held meet-and-greet events at three of Richmond’s largest businesses: manufacturing firm MeadWestVaco, holding company Markel Corp. and law firm McGuireWoods.

Cantor wanted to reach his traditional core voter, persuading white-collar professionals to turn out. On the final weekend of the race, Cantor also met supporters at the homes of loyalists. But he reached only a small swath of a huge district and met largely with people who were already in his camp.

“The congressman told me as he left my house — we’ll be okay if we get out the vote,” said Alan Kirshner, the chief executive of Markel Corp., who hosted a party for more than 100 Cantor supporters at his home in Doswell on Sunday.

As the campaign wound down, even McLaughlin got a sense that Cantor might be in trouble. But, “by then, it’s too late to poll,” he said.

Then came Tuesday itself. Cantor started the day at a Capitol Hill Starbucks, holding his monthly fundraising coffee with lobbyists around 8 a.m. In this case, he was raising money for three junior lawmakers — building the kind of loyalty that would help Cantor ascend to the speaker’s chair when John A. Boehner (R-Ohio) retired. Over coffee, Cantor assured the group of 20 or so that he would win. He had spent heavily, he told them, with the intention of getting a big margin so he would “show no sign of weakness.”

Cantor went to the Capitol, where he met with Republicans in a caucus meeting. Then, as usual, he oversaw the GOP operation on the House floor. Cantor cast 12 votes, the last one at about 3 p.m.

At some point in the late afternoon, Cantor headed down Interstate 95 to Richmond for his victory party. Already, the first hints of real trouble were filtering in to his campaign headquarters. Turnout was much higher than usual, his pollster said.

At 7 p.m., the polls closed, and results began to come in. It was quickly apparent that Cantor would lose.

A few moments later, he appeared on another hotel room stage in Richmond.

“I know there’s a lot of long faces here tonight,” Cantor told the crowd. “It’s disappointing, sure. But I believe in this country. I believe there’s opportunity around the next corner for all of us.”

Then he climbed into a sport-utility vehicle and left, into a life wildly divergent from the one he’d lived that morning. On Wednesday afternoon, Cantor was asked at a Capitol Hill news conference what had happened to cause his sudden fall.

“You know, I’m going to leave the political analysis to y’all,” Cantor said.

Dan Balz, Paul Kane, Antonio Olivo, Robert Costa, Matea Gold and Laura Vozzella contributed to this report.