Only two incumbent San Francisco sheriffs have lost re-election in the last 60 years — but Ross Mirkarimi is facing a tough battle Tuesday to avoid being the third.

The San Francisco sheriff's office has been in the spotlight since a Mexican national in the country illegally was accused in the fatal shooting of a San Francisco woman this summer. The man had been released from Mirkarimi's jail even though federal immigration officials had requested that he be detained.

Also, Mirkarimi has endured a series of personal and official embarrassments, including having his driver's license briefly suspended and flunking a marksmanship test that prevents him from carrying a service weapon.

"I'm in the redemption industry," said Mirkarimi, 54, who launched the Green Party in California before changing his voter registration to Democrat. "I believe in second chances."

His opponent, retired sheriff's official Vicki Hennessy, 62, is running a low-key campaign — her first — hoping to capitalize on Mirkarimi's negative image.

"The department needs leadership," Hennessy said. "It needs its credibility restored."

The latest campaign contribution disclosures show that she has raised $286,000 to his $109,000 and won the endorsements of the unions representing the county jail's sworn officers. Hennessy is also supported by the mayor.

Mirkarimi, who served for eight years on the city's Board of Supervisors, has won the endorsement of the previous sheriff, who served for 32 years before retiring in 2011. Former Mayor Art Agnos also has endorsed Mirkarimi, who points to the success of the jail's high school and the dramatic reduction of the inmate population as major accomplishments.

Hennessy said she was encouraged to enter the race by Mayor Ed Lee and others because of Mirkarimi's stumbles, which began when he bruised his wife's arm during a New Year's Eve argument in 2011.

"I never expected to run," said Hennessy, who joined the sheriff's department in 1975 and rose to chief deputy, the third-highest ranking position in the office. The San Francisco native retired five years ago after directing the city's emergency services agency. She is married to a retired San Francisco police officer and mother to an adult son and daughter.

Mirkarimi pleaded guilty to a misdemeanor false imprisonment charge on March 13, 2012, and was placed on three years of probation. Lee suspended him a week later, saying he intended to remove him permanently. Lee appointed Hennessy as interim sheriff until the San Francisco Board of Supervisors narrowly rejected Lee's attempt to remove Mirkarimi from office in October 2012.

Today, Mirkarimi and his wife, Eliana Lopez, campaign together at commuter train stops, coffee shops and marijuana dispensaries.

Lopez opposed the prosecution of her husband, saying the criminal case was politically motivated.

"I am not a victim," said Lopez, a Venezuelan-born actress who turned the incident into a one-woman play. The couple has a 6-year-old son.

The pivotal issue in the race is the city's policy of shielding people in the country illegally from the reach of federal immigration officials. Mirkarimi's interpretation of the policy came under scrutiny following the March jail release of an inmate despite a federal immigration request to detain him for possible deportation. A few months later on July 2, the Mexican national is alleged to have shot to death Kate Steinle, 32, as she walked with her father along San Francisco's waterfront.

Mirkarimi said city law prohibits the department from cooperating with federal immigration officials unless they have a warrant, a position criticized by presidential hopefuls Donald Trump and Hillary Clinton along with U.S. Sen. Dianne Feinstein of California and the mayor.

Hennessy 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.

But Hennessy said there are other problems with the department.

Since the shooting of Steinle, Mirkarimi has had his driver's license briefly suspended for failing to properly report a minor accident while driving a department-issued car, and he 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 apologized 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.

Political consultant Dan Newman and other analysts say the election is Hennessy's to lose because of Mirkarimi's problems.

"He imploded before he started," Newman said. "Then he continued with a string of screw ups."