Democratic voters in New York’s 14th Congressional District delivered a shock to the political system Tuesday night, rejecting the fourth-highest-ranking member of the party’s House leadership, Representative Joseph Crowley, in favor of Alexandria Ocasio-Cortez, a 28-year-old former Bernie Sanders campaign organizer who has called for abolishing the nation’s immigration and customs enforcement agency.

In doing so, voters delivered a message to Democrats and Republicans across the country, and perhaps in Albany: The liberal base is fired up, showing up at the polls, and may be ignored only at great political risk.

Ms. Ocasio-Cortez’s victory is a vivid sign of the changing of the guard. In addition to more liberal immigration laws, she ran on a platform calling for Medicare for all and a federal jobs guarantee. She also talked about the housing crisis in New York City, an issue that resonates deeply with many voters here. Her district, which runs through Queens and the Bronx, is majority-minority, but its leadership has yet to reflect those changes. That’s something Ms. Ocasio-Cortez was able to capitalize on fluently, casting herself as part of a new generation of young, unabashedly liberal Democrats unwilling to wait their turn any longer.

Many told Ms. Ocasio-Cortez she was crazy for challenging Mr. Crowley, a 10-term incumbent who had ambitions to succeed the House Democratic leader, Nancy Pelosi of California. As chairman of the Queens County Democratic Party, Mr. Crowley, 56, was a kingmaker in New York City politics. At his annual holiday party, city officials were expected to perform karaoke, singing and dancing on the stage to a song of Mr. Crowley’s choosing.