The San Francisco sheriff who over the summer became embroiled in a national debate over "sanctuary city" policies on Tuesday lost his bid for re-election amid a host of local controversies.

Sheriff Ross Mirkarimi, 54, was defeated by Vicki Hennessy, a former sheriff's official who had the endorsement of San Francisco Mayor Ed Lee and the sheriff deputies association. As of early Wednesday morning, Hennessy had received 62 percent of the vote to just 31 percent for Mirkarimi.

Mirkarimi was the subject of national criticism after Mexican illegal immigrant Francisco Sanchez allegedly shot and killed 32-year-old Kate Steinle on San Francisco's waterfront July 1. Sanchez had been released from Mirkarimi's jail in March even though federal immigration officials had requested he be detained for possible deportation.

But since then, the sheriff's oversight of the department has been plagued by other high-profile mishaps and controversies seen as contributing to his defeat. He had his driver's license briefly suspended for failing to properly report a minor accident while driving a department-issued car, and he also flunked a marksmanship test.

Before those two incidents, a drug gang leader escaped from jail, and guards were accused of staging and gambling on inmate fights.

In November 2014, Mirkarimi also was forced to apologize for the bungled search for a San Francisco General Hospital patient whose body was found in a stairwell weeks after she wandered from her room. The sheriff is in charge of the hospital's security, but deputies didn't search the building until nine days after her disappearance. The city paid the patient's family $3 million to settle a lawsuit.

But Mirkarimi is now known nationally for his strident defense of sanctuary city policies, taking the practice to a new level under his leadership.

San Francisco declared itself a sanctuary city in 1989, passing an ordinance that bans city officials from enforcing immigration laws or asking about immigration status unless required by law or court order. A follow-up ordinance in 2013 allows detention only under a court order targeting violent felons. Last month, San Francisco's board of supervisors unanimously approved a resolution to maintain the city's sanctuary status.

San Francisco and other cities and counties have routinely ignored requests from Immigration and Customs Enforcement officials to keep people in custody. The jurisdictions say they can't hold arrestees beyond their scheduled release dates without probable cause.

Hennessy has previously said the sheriff's order barring the San Francisco jail from cooperating with immigration officials is misguided. There are cases, she said, when federal immigration officials should be notified that the jail is about to release an inmate who is in the country illegally.