Longtime lawmaker and the head of the Queens Democratic machine, Rep. Joe Crowley, lost his bid for re-election in a stunning upset to 28-year-old political newcomer and liberal activist Alexandria Ocasio-Cortez.

Ocasio-Cortez, who identifies as a Democratic socialist, led Crowley by 15 percent — 57 percent to his 42 percent — with 78 percent of the 14th Congressional District’s precincts reporting.

Both the Associated Press and New York 1 project that Ocasio-Cortez has an insurmountable lead.

Crowley’s defeat is a political earthquake in New York City politics where political machines dominate low-turnout elections and incumbents often go unchallenged.

Crowley — a high-ranking house member who had been considered a contender to take over leadership from Rep. Nancy Pelosi — was no exception to that rule. First elected to Congress in 1998, Ocasio-Cortez was the first primary challenge he had faced in 14 years.

He is the first Democratic congressperson to lose re-election in a primary since Rep. Stephen Solarz 1992. And Solarz was running for essentially a new seat after redistricting dismantled his longtime district.

Ocasio-Cortez was endorsed by the New York City Democratic Socialists of America and recently told Vogue she was a member of the group because: “When we talk about the word socialism, I think what it really means is just democratic participation in our economic dignity, and our economic, social, and racial dignity.”