Baltimore City State's Attorney candidate Ivan Bates (left) and Rachael Rice (right) watch results come in at Bates' election night event. Maryland held its primary election on Tuesday, July 19.

Challenger Ivan Bates jumped ahead and held his lead through the night Tuesday in the highly anticipated race for Baltimore state’s attorney.

The defense attorney won about 41% of votes counted Tuesday, leading incumbent Marilyn Mosby and challenger Thiru Vignarajah. They received about 32% and 27%, respectively.

Mosby and Vignarajah did not concede and encouraged their supporters to hold out hope for the mail-in ballots. Nearly 44,000 ballots were mailed to city Democrats, and they remain to be counted this week.

Bates expressed optimism about his chances of unseating the controversial two-term state’s attorney.

“We started out well, but still a long ways to go,” he said. “Remember Mrs. Mosby is the incumbent state’s attorney and is an actual champion, has won time after time after time, so we’ll see what happens. We’re cautiously optimistic.”

As the polls closed, Bates supporters shuffled into the Village Learning Place in Charles Village, entering through a small garden with a live band in the corner. Bates made his rounds, hugging and shaking hands with people holding plates of grilled chicken, macaroni and cheese and greens. Some 50 supporters turned out to watch the results with him.

”No matter what happens today — win, lose or draw — we ran a really phenomenal campaign,” Bates told them.

He had a long list of thank-you’s, but at the top was his 6-year-old daughter whom he hopes understands when she’s older the sacrifices he made during the campaign. Her energy, he said, gave him the stamina to get through it all.

Before heading home early, Bates said a win would only be their start to addressing the change that Baltimore needs.

”If we are blessed enough to win, we have a lot of work to do for the city. We made a lot of promises and plans,” he said. “And one of the things I don’t like to see is politicians who promise and get in office and forget the people.”

Bates was leading Mosby by more than 4,000 votes as of midnight, with 284 of 296 precincts reporting results. Elections officials won’t begin counting mail-in ballots until Thursday.

Surrounded by family and supporters, Baltimore City State’s Attorney Marilyn Mosby takes the stage to address the crowd at Melba’s Place shortly before midnight the day of Maryland primary election.

Speaking to supporters at Melba’s Place in Waverly shortly after 11:30 p.m., Mosby thanked her family, employees and members of the campaign. She addressed the crowd for about 10 minutes. Her husband, Baltimore City Council President Nick Mosby, stood at her side.

“I’m going to fight — the same way I fought to get into this position — until every single vote is counted,” she told the crowd.

Four years ago, Mosby defeated the two men with 49% of the vote. Bates took 28% and Vignarajah 22.5%.

Mosby, 42, of Reservoir Hill, makes about $248,000 a year. Bates, 53, lives in Locust Point and worked as a city prosecutor before opening the defense firm Bates and Garcia, LLC.

Vignarajah, 45, lives in Federal Hill and served as a city, state and federal prosecutor. He is CEO of Capital Plus Financial, a Texas-based financial institution that lends money to projects of social impact.

“Our formula has always been that those reliable, dedicated voters who care deeply about this city, that mail in their ballots, are our bread and butter,” Vignarajah said among his campaign in Canton. “They’re the foundation of our vision of this city: 20,000 are already in, and won’t start getting counted until Thursday. That’s already more than the ballots that are in tonight, and we think we have a big lead among those mail in ballots.”

An independent candidate, defense attorney Roya Hanna, will face the winner in November’s general election.

Across Baltimore, residents cast their ballots Tuesday citing crime and the dramas swirling around the race.

Clarence McNair, 65, pumped his fist in the air and cheered after voting at the Enoch Pratt Free Library’s branch in Mount Vernon — his worn, marked up sample ballot in one hand and his “I voted” sticker in the other.

McNair recently retired from Johns Hopkins Bayview Medical Center and said he voted for Vignarajah over incumbent Mosby. “Change has got to come.”

”This city is in crisis just like they say, and we can’t patch things up anymore,” he said. “We really have problems, and we need someone who can fix them.”

Meanwhile, at the Pratt library on Pennsylvania Avenue, Stephanie Washington said she was voting for Bates along with Peter Franchot for governor.

”I just want the right people to get in office. I don’t want to hear no drama about anyone’s life,” she said, referring to Mosby.

Washington said she’s passionate about young people who grow up in Baltimore and would like to see more solutions to homelessness, vacant housing, gun violence and drug abuse.

“We need to rebuild Baltimore — period,” she said.

Marvin Washington, 68, of West Baltimore, shared the excitement about the state’s attorney’s race. Washington said he’s worried about gun violence, and he supports Mosby.

“It seems like they’re trying to kick her out,” Washington said. “I’m voting to try to keep her in.”

Mosby took office in 2015 as the youngest top prosecutor of any major U.S. city. In three months, she sparked national debate by charging six Baltimore police officers in the arrest and death of Freddie Gray. None were convicted.

Her decision to charge the officers thrust Mosby into the spotlight, and she positioned herself in the years following as a leading figure in progressive criminal justice reforms. She directed her office to stop prosecuting people for possessing marijuana, and then for nonviolent crimes such as any drug possession, prostitution and trespassing. She assembled a unit to review cases of men who have been wrongfully convicted and set them free.

Still, her political opponents have sought to blame Mosby for the street violence that continues to grip Baltimore. The city has suffered more than 300 killings for each year of Mosby’s tenure. That’s made her a bogeyman in conservative politics. In Harford and Carroll counties, state’s attorney candidates have sought to compare their rivals to Mosby as a way to put off voters.

Mosby’s last four years have been shadowed by controversies. In January, a federal grand jury indicted her on charges of perjury and making false statements on loan applications. She’s accused of a sequence of dishonest financial moves that enabled her to buy two vacation homes in Florida worth more than $1 million combined. She’s scheduled for trial in September.

In response to the charges, Mosby has come after federal prosecutors and accused them of unfairly singling her out because of her race, gender and politics. A federal judge found no merit in her claims of a vindictive prosecution and ordered her to trial.

It’s not entirely clear what happens if Mosby wins re-election only to be convicted. The Maryland Constitution establishes that a state’s attorney “be subject to removal therefrom, for incompetency, willful neglect of duty, or misdemeanor in office, on conviction in a Court of Law.”

In the case of a vacancy, judges appoint a successor.

Similarly, a conviction could open the door for bar counsel of the Attorney Grievance Commission to try and strip her of her law license. A state’s attorney must be licensed to practice law.

Reporters Jessica Calefati, Hallie Miller and Dylan Segelbaum contributed to this story.