In an upset, former Philadelphia Police Officer Rochelle Bilal beat incumbent Sheriff Jewell Williams in the Democratic primary Tuesday, ousting a party stalwart who was seeking a third term with the baggage of three sexual harassment lawsuits.

Bilal, 61, will likely be the first woman elected sheriff. She is president of the Guardian Civic League, a group that represents black police officers, and also secretary of the local NAACP chapter.

With 97 percent of returns in, Bilal was leading the four-way race by about 22,000 votes. It was a crushing defeat for Williams, who has been in elected office since 2001, first as a state representative. He has been sheriff since 2012.

“I’ve never run for office before, and I’m exhausted, but I’m excited,” Bilal said. “I’m excited that people in this city saw something different and voted for us.”

Two former sheriff’s deputies, Malika Rahman and Larry King Sr., also were trying to oust Williams.

Sheriff is an independently elected office charged with court security, transporting prisoners to court, and managing court-ordered sales of foreclosed and tax-delinquent properties. It has a $26 million budget and 400 employees.

The race for sheriff was a rather quiet affair, with Williams’ challengers, including Bilal, raising a fraction of what Williams raised and keeping low profiles other than to attend candidate forums. Williams avoided much of the campaign limelight, opting to skip most candidate forums and declining to give interviews to reporters.

In the last year, news surfaced of three sexual harassment lawsuits against Williams; two were settled and one is pending. He has vehemently denied all three allegations. Mayor Jim Kenney and some City Council members called for the sheriff to resign. The Democratic City Committee reversed its decision to endorse Williams, following a significant backlash.

“I think women have spoken," Kenney said Tuesday when asked about Williams’ loss.

Nevertheless, many of the Democratic wards had Williams on Tuesday’s sample ballots at the polls.

Bilal had her own brush with controversy when she was with the Police Department. She retired in 2013 amid an investigation into a second job she had with Colwyn Borough. In an interview with The Inquirer, Bilal said she kept the two separate and was not double-dipping. She was eventually let go from the Colwyn job, but said that she sued the township for wrongful termination and received a settlement. (Officials at Colwyn did not respond to a request for information on the case and reported settlement.)

Throughout the campaign, Bilal said she wants to prevent homes from even going to sheriff’s sale. She was critical of Williams’ use of millions of dollars to advertise sales in various newspapers. She instead wants to pay for community programs to help “distressed” families.

She also vowed to implement a sexual harassment policy on Day One.

“People were just tired of scandal after scandal in the Sheriff’s Office and many didn’t know what the Sheriff’s Office is." Bilal said. "Now they will know.”

Through a spokeswoman, Williams declined to comment Tuesday evening. The spokeswoman said he had not conceded.

Williams was first elected sheriff in 2012, promising transparency and reform. But he quickly drew controversy for requesting new cars and bigger staff. The budget and number of employees ballooned under his watch. He also added more duties to the office, including serving warrants, and guarding City Council and the new Family Courthouse, which helped justify his need for more staff.

The Sheriff’s Office has been plagued by scandal for years. Former Sheriff John Green, who had resigned, pleaded guilty last month to felony conspiracy charges that he steered $35 million in contracts to a campaign contributor who also showered him with gifts, including home renovations and a no-interest loan.

With no Republican opposition, Bilal is poised to win the general election in November unless an independent qualifies for the ballot and then pulls in more votes than she does. If she wins in the fall, Bilal will be the first woman to be Philadelphia sheriff.

Staff writer Laura McCrystal contributed to this article.