Progressive candidate Abdul El-Sayed won Michigan's Democratic Senate primary Tuesday, defeating centrist U.S. Rep. Haley Stevens in a closely watched race that exposed the Democratic Party's ideological divide.

NBC News was the first to project El-Sayed as the winner after a lengthy vote count, giving progressives a major victory in a battleground state where moderates had argued Stevens was the stronger general election candidate.

The race remained too close to call for much of the night as Wayne County, home to Detroit, slowly reported results. El-Sayed led early before Stevens narrowed the gap, but she was unable to overtake him.

"We knew that this was going to be a close race, and that's exactly what we've got," Stevens told supporters before the race was called.

Speaking to supporters as the count continued, El-Sayed urged Democrats to unite behind the eventual nominee.

"Whatever happens tonight, we have a responsibility to ensure that we unite ... to make sure that Mike Rogers never sees the inside of the U.S. Senate," he said.

The expensive primary became a national proxy fight between the Democratic establishment and the party's progressive wing. While progressive candidates have won in heavily Democratic cities in recent years, El-Sayed's victory in politically competitive Michigan is likely to be viewed as a more significant test of the movement's strength.

El-Sayed, the former Wayne County health director, campaigned on a platform that included Medicare for All, campaign finance reform and ending U.S. military aid to Israel. Stevens, a four-term congresswoman, centered her campaign on manufacturing, the economy and her record of winning competitive elections, arguing she was best positioned to defeat Republican Mike Rogers in November.

Stevens was backed by Senate Minority Leader Chuck Schumer and benefited from tens of millions of dollars in outside spending, including major support from pro-Israel groups led by AIPAC. El-Sayed was endorsed by Sen. Bernie Sanders and campaigned as an anti-establishment candidate, arguing Democrats should reject corporate influence and embrace a more progressive agenda.

The contrasting messages resonated with different voters.

Kenneth Woodside, 87, of West Bloomfield, said he backed El-Sayed because "the nation is ready for someone who wants to take some more action rather than on the road we are now, which is on the road to an oligarchy and authoritarianism."

Nessa Fuller, 51, of Birmingham, said she voted for Stevens because she believed the congresswoman would "fight to get the right things done, and she'll work with other people, which is really important to me."

Outside groups spent more than $50 million backing Stevens, including more than $30 million from AIPAC and affiliated organizations, making the contest one of the most expensive Senate primaries in the country. The spending thrust Israel policy into the spotlight, with El-Sayed calling for an end to U.S. military aid to Israel while Stevens defended the U.S.-Israel alliance.

Michigan voters also picked nominees in several other high-profile races.

On the Republican side of the governor's race, U.S. Rep. John James, who was endorsed by President Donald Trump, defeated businessman Perry Johnson. Democratic voters nominated Secretary of State Jocelyn Benson over Genesee County Sheriff Chris Swanson.

Several competitive House races were also decided ahead of November, when control of both the House and Senate will again be on the line.