In a letter of resignation filed Wednesday with the city clerk's office, Klein cited "major setbacks" in his personal life that he said made it impossible to continue on as a public servant.
Klein, who was elected to a four-year term on the council in 2009, said in the letter that he and his wife had decided to "dissolve" their marriage.
"While juggling my personal and public life I have not afforded myself the time and care to appropriately cope with this loss," Klein wrote. "I have made decisions in my personal life that have become detrimental to myself and others."
He did not say what those decisions were.
"I have begun treatment to address my situation and ask everyone to allow me the time and privacy to do so," Klein said.
City Councilman Matt Grocott will become interim mayor until the city council addresses the vacancy, according to the city manager's office.
Klein was arrested by the California Highway Patrol on suspicion of driving under the influence in mid-May, but the San Mateo County District Attorney's Office declined to file charges, saying tests taken at the time of the arrest showed Klein's blood-alcohol content at .07 percent, below the legal limit.
Klein was selected as mayor by his council colleagues in June after former Mayor Omar Ahmad died suddenly of a heart attack on May 10.