Stringer had a 52-percent-to-48-percent lead over Spitzer in incomplete and unofficial returns, with 92 percent of precincts reporting. Spitzer conceded a race he had upended by jumping into it just two months ago.
"When it was very tough out there, nobody walked away," Stringer told cheering supporters shortly afterward. "...I'll make sure that I make you proud."
Stringer will face a Republican and other opponents in November's general election. Almost 70 percent of city voters are Democrats, and Democrats have held the comptroller's office for decades.
Stringer has held office for two decades as borough president and a state assemblyman. He was heavily favored in the comptroller race before the former governor turned a tame campaign into a slugfest.
Nonetheless, Spitzer told supporters Tuesday night he was proud to have run a campaign many thought impossible even to conduct.
"We did it in a way that made me proud to revisit the issues we fought for" when he was in Albany, he said.
Stringer had argued that voters should spurn a politician who resigned amid a prostitution scandal. He offered himself as a veteran, untarnished public servant who knows how to work with others to make government work.
"Nobody should be elected to office who resigned in disgrace," Stringer said at a candidate forum last week. "I have the temperament. I have the experience."
Spitzer, though, bet that his assertive, ambitious turns as attorney general and governor would persuade the city to give him another chance after illegal liaisons spurred his resignation five years ago.
His message was simple: "I made mistakes, but I made a difference."
That resonated with Paulette Esrig, 81, a retired schoolteacher who voted for him Tuesday in Manhattan.
"I picked him not because I approve of his personal life at all, but I felt he was well qualified," she said.
But other voters said Spitzer's past scandal drove them to pull levers for Stringer, even if they didn't know much about him.
"He's not my favorite, but I think Spitzer is an abomination," said Julian Stark, 55, a college biology professor, who also voted in Manhattan.
Spitzer stepped down after being identified as a client of an escort service that was under federal investigation. The married Spitzer was never criminally charged but later acknowledged he'd paid for sex.
Spitzer unexpectedly plunged back into campaigning just four days before the deadline to get on the primary ballot. Dubbed "the sheriff of Wall Street" as attorney general, he styled himself as a leader unafraid to take on powerful interests or take up unpopular causes.
But where Spitzer trumpeted "independence," Stringer shot back with "integrity." He branded the ex-governor a master of hubris who was using his personal fortune to seek political redemption after breaking laws he swore to uphold.
Spitzer dismissed his opponent as "a status-quo voice for 20 years" who didn't have the spirit or skills to make the city's chief financial office a greater force for accountability in government and change in corporate practices.
Much of the city's Democratic political establishment rallied around Stringer, and he was endorsed by newspapers including the Daily News, the New York Post and The New York Times.
Exit polls conducted by Edison Media Research for The Associated Press and other news organizations showed Spitzer leading among black voters by 66 percent to 34 percent, while Stringer carried the white vote 67 percent to 33 percent. Hispanics tilted toward Spitzer, 54 percent to 45 percent. And in a contest among two Jewish candidates, 69 percent of Jewish voters supported Stringer, compared to 31 percent for Spitzer.
The preliminary exit poll of 2,035 Democratic primary voters was conducted in a random sample of 40 precincts citywide. Results have a margin of sampling error of plus or minus 4.0 percentage points; it is higher for subgroups.
The comptroller audits city agencies, analyzes the budget and invests city workers' nearly $140 billion pension funds, among other responsibilities. Incumbent John Liu ran for mayor, an effort that ended with a fourth-place finish in Tuesday's Democratic primary.
Adding to the unconventional comptroller race, former madam Kristin Davis declared a third-party candidacy in April and was arrested in August on prescription drug sale charges; she denies them. She ultimately didn't file petitions to get on the ballot, according to the city Board of Elections. She didn't immediately respond to an email inquiry Tuesday.
Associated Press writer Jake Pearson, AP Radio Correspondent Julie Walker and AP Video Journalist Ted Shaffrey contributed to this story.