House Democratic Caucus Chair Joseph Crowley, D-N.Y., seen in February, was beaten Tuesday by a 28-year-old supporter of Bernie Sanders.

NEW YORK — As Donald Trump’s party came together, a 28-year-old liberal activist ousted top House Democrat Joe Crowley in the president’s hometown Tuesday night, a stunning defeat that suddenly forced Democrats to confront their own internal divisions.

Crowley, the No. 4 House Democrat and until Tuesday considered a possible candidate to replace Nancy Pelosi as leader, becomes the first Democratic incumbent to fall this primary season. He was beaten by underfunded challenger Alexandria Ocasio-Cortez, the daughter of working-class immigrants and a former Bernie Sanders organizer who caught fire with the party’s left wing.

Crowley’s loss echoed across the political world, sending the unmistakable message that divisions between the Democratic Party’s pragmatic and more liberal wings may be widening heading into the high-stakes November midterm elections. It also exposed a generational divide among Democrats still struggling with their identity in the Trump era.

“The community is ready for a movement of economic and social justice. That is what we tried to deliver,” Ocasio-Cortez said in an interview with The Associated Press.

Trump, on social media at least, seemed equally excited about Crowley’s defeat.

“Perhaps he should have been nicer, and more respectful, to his President!” Trump tweeted, oddly taking credit for a victory by a candidate more liberal than Crowley. He added: “The Democrats are in Turmoil!”

All in all, Trump had reason to celebrate Tuesday night as all three of his endorsed candidates survived primary challenges that could have embarrassed him and the party.

Those included New York Rep. Dan Donovan, who defeated convicted felon Michael Grimm in New York City’s only Republican stronghold, and former Republican presidential nominee Mitt Romney, who once branded Trump “a fraud” but has warmed to the president in the past two years.

Yet none of the day’s contests mattered more to Trump than the one in South Carolina.

Gov. Henry McMaster, one of the president’s earliest and strongest supporters, survived an unusually tough challenge from a political newcomer, self-made Republican millionaire John Warren.

The White House went all-in for the governor in recent days, dispatching the president and the vice president to the state in an effort to prevent a political debacle.

Trump’s party did just that on Tuesday, though the president has a mixed track record when weighing in on party primaries: His preferred candidates have suffered stinging losses in Alabama and western Pennsylvania in recent months.

With the November general election a little more than four months away, more than half the states had selected their candidates after the day’s final votes were counted across South Carolina, New York, Oklahoma, Mississippi, Maryland, Colorado and Utah.

History suggests that Trump’s Republican Party, like the parties of virtually every first-term president dating back to Ronald Reagan in 1982, will suffer losses this fall.

Yet Crowley’s loss suggests that Democrats must overcome intraparty divisions if they hope to take control of Congress and key governors’ offices nationwide.

In New York, Ocasio-Cortez cast Crowley as an elitist out of touch with the community.

“This race is about people versus money. We’ve got people, they’ve got money,” Ocasio-Cortez said in biographical web ad that followed her through mundane New York life, dressing for work, walking, changing into high heels on the subway platform. “Women like me aren’t supposed to run for office.”

Trump got more good news elsewhere in New York City as Grimm failed in his political comeback attempt at the hands of the Trump-backed incumbent Donovan.

Grimm had held the Staten Island seat until 2015, when he pleaded guilty to knowingly hiring immigrants who were in the country illegally to work at his Manhattan restaurant and cooking the books to hide income and evade taxes.

More than 2,000 miles (3,200 kilometers) away in deep-red Utah, former Massachusetts Gov. Romney defeated little-known state Rep. Mike Kennedy, who questioned Romney’s conservative credentials and ability to work well with the president. Romney, too, was endorsed by Trump despite his aggressive criticism of the president before his election.

In a weekend op-ed published in The Salt Lake Tribune, Romney wrote that the Trump administration’s policies have exceeded his expectations, but he pledged to “continue to speak out when the president says or does something which is divisive, racist, sexist, anti-immigrant, dishonest or destructive to democratic institutions.”

Trump cheered Romney’s win on social media: “I look forward to working together – there is so much good to do. A great and loving family will be coming to D.C.”

Not to be forgotten: races to determine gubernatorial candidates in Maryland, Colorado and Oklahoma.

In Maryland, former NAACP President Ben Jealous seized the Democratic governor’s nomination. He would become the state’s first African-American governor if he beats Republican incumbent Gov. Larry Hogan this fall.

In Colorado, five-term Democratic congressman Jared Polis won the Democratic nomination in the race to replace outgoing Democratic Gov. John Hickenlooper. And in Oklahoma, former state Attorney General Drew Edmondson beat former state Sen. Connie Johnson to win the Democratic nomination in the race to be the state’s next governor.

Oklahoma voters also backed the medicinal use of marijuana despite opposition from law enforcement and business, faith and political leaders.

But Crowley’s defeat overshadowed much of the day’s developments.

He becomes the first congressional leader to fall in a party primary since former Republican House Majority Leader Eric Cantor was stunned by unknown conservative Dave Brat in 2014’s midterm election.

That loss, and perhaps this one, cemented the GOP’s sharp shift away from the political center and foreshadowed the anti-establishment fervor that fueled Trump’s election in 2016.

And while Trump cheered Crowley’s downfall, so did liberal leaders who backed Ocasio-Cortez.

“These results are also a shot across the bow of the Democratic establishment in Washington: a young, diverse, and boldly progressive Resistance Movement isn’t waiting to be anointed by the powers that be,” said Matt Blizek, of MoveOn.