WASHINGTON – House Majority Leader Eric Cantor announced Wednesday that he will resign his leadership post at the end of next month, clearing the way for a potentially disruptive Republican shake-up just before midterm elections with control of Congress at stake.

Cantor informed fellow Republicans of his intentions at an emotional closed-door meeting, then made his public announcement at a news conference where he appeared upbeat, all less than 24 hours after losing a primary election to David Brat, a little-known and underfunded rival backed by the ultraconservative tea party wing of the Republican party.

Lawmakers in both parties said Cantor’s defeat and the prospect of a change within the Republican high command probably signal the demise of immigration legislation along the lines President Barack Obama is seeking and will also have a negative impact on the balance of his second-term agenda.

Even so, Obama disputed the notion that Cantor’s surprise loss crushed the prospects of House Republican leaders putting an immigration bill on the floor this year.

“It’s interesting to listen to the pundits and the analysts, and some conventional wisdom talks about how the politics of immigration reform seem impossible now,” Obama told about 40 big-dollar donors a Boston suburb. “I fundamentally reject that and I will tell the speaker of the House he needs to reject it.”

White House spokesman Josh Earnest noted that Republican Sen. Lindsey Graham had been deeply involved in passing the Senate immigration bill and still defeated his primary opponents Tuesday night.

Cantor also has been deeply involved in Republican attempts to develop an alternative to Obama’s health care law that Republicans want to repeal.

Fellow Republicans set leadership elections for June 19, assuring that any campaigning would be brief.

Even before Cantor’s announcement, jockeying had broken out among fellow Republicans eager to move up the House leadership ladder — or establish a foothold on it.

Rep. Kevin McCarthy, the party whip and third-ranking leader, informed fellow Republicans he intended to run to succeed Cantor. Rep. Pete Sessions also made clear his interest, but fellow Texan Jeb Hensarling eyed a candidacy, as well, and the state’s delegation was working to prevent any intramural competition.

Cantor, 51, sounded like anything but a man ready to retire from politics, saying he will serve out his term and be active this fall for Republican candidates.

“What divides Republicans pales in comparison to what divides us as conservatives from the left and their Democratic” allies, he said.

Accused by tea party critics of being too accommodating on immigration and other issues, and criticized by Democrats for being inflexible, Cantor said he had struck the right balance. “I think that this town should be about trying to strike common ground,” he said.

The resignation marks a swift end to a quick rise to power for Cantor, 51, who was elected to Congress in 2000, was appointed to the leadership two years later, and then rose steadily to become the second-most powerful Republican in the House. In that post, he was the most powerful Jewish Republican in Congress, and occasionally was seen as a potential rival to Speaker John Boehner but more often as a likely successor.

Brat campaigned as a foe of immigration legislation, and said Cantor was likely to help immigrants living in the United States illegally gain amnesty if given a new term in the House.

Brat begins the fall campaign as a decided favourite in the race against Democratic rival Jack Trammell in a solidly Republican Richmond-area district.

His primary triumph was by far the biggest of the 2014 campaign season for tea party forces, although last week they forced veteran Mississippi Sen. Thad Cochran into a June 24 runoff and they hope state Sen. Chris McDaniel will achieve victory then.

The impact of Cantor’s surprise loss on the fate of immigration legislation in the current Congress seemed clear. Conservatives will now be emboldened in their opposition to legislation to create a path to citizenship for immigrants living in the country illegally, and party leaders who are sympathetic to such legislation will likely be less willing to try.

___

Associated Press writers Andrew Taylor, Alan Fram and Erica Werner in Washington contributed to this report.