She has never held elected office. She is still paying off her student loans. She is 28 years old. “Women like me aren’t supposed to run for office,” Alexandria Ocasio-Cortez said in a viral campaign video released last month.

They certainly weren’t supposed to win.

But in a stunning upset Tuesday night that ignited the New York and national political worlds, Ms. Ocasio-Cortez, a Bronx-born community organizer and member of the Democratic Socialists of America, defeated Representative Joseph Crowley, a 19-year incumbent and Queens political stalwart who had not faced a primary challenger in 14 years.

Mr. Crowley, who is twice Ms. Ocasio-Cortez’s age, is the No. 4 Democrat in the House of Representatives and had been favored to ascend to the speaker’s lectern if Democrats retook the lower chamber this fall.

If Ms. Ocasio-Cortez defeats the Republican candidate, Anthony Pappas, in the predominantly Democratic district in November, she would dethrone Elise Stefanik, a Republican representative from upstate New York, as the youngest woman ever elected to Congress (Ms. Stefanik was 30 when she took office in 2015).