Marilyn J. Mosby defeated Baltimore City State's Attorney Gregg L. Bernstein on Tuesday after criticizing him for failing to live up to promises he made four years ago to win the office.
Bernstein conceded shortly before 11:30 p.m. Tuesday.
"We have left the office in a much better place," Bernstein said, "an office that is more effective, more efficient and more professional."
When Bernstein took office in 2011 after defeating incumbent Patricia C. Jessamy, he promised to boost conviction rates and focus on violent crime in Baltimore.
But Mosby, 34, a former city prosecutor who now works for an insurance company, argued that he was failing.
Mosby said the work of her campaign involved going door to door and "convincing people who had never heard of me, one at a time, that I was the woman who would bring change to the state's attorney office."
Mosby portrayed Bernstein as out of touch with the city and chided him for moving prosecutors into new suites in a downtown skyscraper and said he had done too little in his central mission of targeting violent repeat offenders. She pointed to cases in which defendants who recently walked out of court were accused in subsequent killings.
Bernstein, 58, reorganized the office and drew on his experience as a federal prosecutor to develop sophisticated conspiracy cases aimed at bringing down whole gangs.
In a confident, low-key campaign, he touted a greater rate of felony convictions than his predecessor.
No Republican filed to run for the job. The winner of the Democratic primary could face local defense attorney Russell A. Neverdon Sr. in the general election. Neverdon is gathering signatures to secure a place on the ballot as an independent.
Neverdon said Tuesday that he had been following the Democratic race closely and was ready to take on the winner.
"I'm not challenging either one of them," he said. "I'm just offering Baltimore City a choice for change."
The vote Tuesday ended a long campaign that began last year amid an especially bloody span, during which the rising number of shootings and killings rattled Baltimoreans.
Initially, Bernstein declined to engage his opponent. He brushed off questions about Mosby's challenge by saying he was focused on running the state's attorney's office. But behind the scenes he was raising a huge campaign fund — by mid-June he had pulled in almost $630,000 to Mosby's $200,000.
Mosby, the wife of City Council member Nick Mosby, secured endorsements from former congressman and NAACP leader Kweisi Mfume and from many of her husband's colleagues. She maintained an active presence on social media and sent out letters criticizing Bernstein.
In the days before the primary, the tone of the campaign grew increasingly bitter.
WBAL-TV aired a story last week asking whether Bernstein had a conflict of interest in a police overtime investigation, and Mosby attacked him as too close to some members of the Police Department.
Bernstein's camp struck back by saying that Mosby was unready for the job, and filed an election-law complaint against her campaign on the eve of the vote.
Seven members of the Circuit Court bench fended off a challenge from former prosecutor Page Croyder. She said she decided to run to try to knock Alfred Nance from his seat.
Croyder did not run directly against Nance. In the Circuit Court elections, individual candidates run in both the Democratic and Republican primaries at the same time.
This year, the same seven from each primary will advance to the general election in November.
Sheriff John W. Anderson, who has been in office for 25 years, beat back two Democratic challengers.
School police officer Donoven Brooks had said Anderson's public profile was too low. Community activist Richard M. Parker called for an audit of the office. Both candidates had accused Brooks of mismanagement.
But Anderson, who had the backing of the union that represents his deputies, had pointed to his record in office and had worked closely with city police to serve warrants on violent offenders.
He will face Republican David A. Wiggins in the general election.
Former City Council member Belinda K. Conaway won the Democratic primary for register of wills. The job was held by her stepmother, Mary W. Conaway, from 1982 until her retirement in 2012.
Baltimore Sun reporters Colin Campbell and Will Fesperman contributed to this article.