Rep. Joe Crowley, chairman of the House Democratic Caucus, lost his primary election in New York Tuesday to an acolyte of Sen. Bernard Sanders.

The loss stunned political observers and thrilled liberal activists who called Alexandria Ocasio-Cortez’s win a “seismic victory” for the forces seeking to push the Democratic Party to the left.

Mr. Crowley, a 20-year incumbent, had drastically outspent Ms. Ocasio-Cortez, but activists said she rode a wave of voter discontent

“Alexandria Ocasio-Cortez and the army of grassroots volunteers who delivered this jaw-dropping victory tonight didn’t just win a difficult race, they won a primary campaign that most laughed at them for even waging,” said Jim Dean, chairman of Democracy for America.

Ms. Ocasio-Cortez, 28, was an organizer for Mr. Sanders and ran on a Sanders-esque platform of universal government-sponsored health care, tuition-free college and a federal jobs guarantee.

On Twitter, she said she tapped into voters who never turn out for congressional primary elections.

Her victory was akin to the 2014 primary election loss of then-House Majority Leader Eric Cantor, a Virginia Republican who was ousted by a tea party-backed candidate.

Mr. Crowley, while not as high in the Democratic leadership ranks, is still an outsized personality on Capitol Hill, and had been seen as a contender for the party’s top House role, should Rep. Nancy Pelosi step down.

His loss will reverberate among Democrats trying to figure out how to marry the party’s establishment with its energetic left wing.

President Trump crowed over the news.

“Wow! Big Trump Hater Congressman Joe Crowley, who many expected was going to take Nancy Pelosi’s place, just LOST his primary election,” the president said on Twitter. “In other words, he’s out! That is a big one that nobody saw happening. Perhaps he should have been nicer, and more respectful, to his President!”

Mr. Sanders also weighed in, calling Ms. Ocasio-Cortez’s victory an “extraordinary upset.”

“She took on the entire local Democratic establishment in her district and won a very strong victory. She demonstrated once again what progressive grassroots politics can do,” he said.