Lee's term expired in January 2012, when the winner of the November 2011 mayoral election would assume office. Lee originally pledged not to run in that election. However, some San Francisco political activists – including Rose Pak, consultant for the San Francisco Chinese Chamber of Commerce, Planning Commission President Christina Olague, Assistant District Attorney Victor Hwang, 'Progress for All' chief consultant, Enrique Pearce and Eddy Zheng – started a "Run Ed Run" campaign in June 2011 to encourage him to put his name on the ballot. By July 28, Lee stated that he had visited his daughters in Washington state and discussed with them the possibility of running, but had still not made up his mind. Senator Dianne Feinstein, herself a former appointee mayor who had gone on to win reelection for two terms, publicly supported a Lee candidacy. The San Francisco Chronicle wrote that unnamed city officials close to Lee told the media that Lee had "nearly finalized his decision" to run.
In 2012, Lee proposed the creation of a Housing Trust Fund, which would generate between $20 million and $50 million of funding for affordable and middle class housing per year for thirty years. In 2014, Lee and David Chiu, the President of the Board of Supervisors, announced the creation of the Ellis Act Housing Preference Program, which would help people evicted from their homes by landlords using the Ellis Act. That year, Lee pledged to construct 30,000 new and rehabilitated homes throughout the city by 2020, with half available to low, working and middle income San Franciscans, and launched a small site acquisition program to fund the purchase and stabilization of multi-family rental buildings in neighborhoods that are susceptible to evictions and rising rents. Lee sponsored a $310 million bond measure to pay for housing for the November 2015 general election, which passed. In 2017, Lee approved a $44 million project to build affordable housing for teachers.
On January 13, 2012, incumbent Sheriff Ross Mirkarimi was charged with domestic violence battery, child endangerment, and dissuading a witness in connection with a New Year's Eve altercation he had with his wife. On March 20, 2012, Mayor Ed Lee gave Sheriff Mirkarimi a 24-hour ultimatum to resign from his post. While jury selection was underway, Mirkarimi entered into a plea agreement with the district attorney and pled guilty to one count of misdemeanor false imprisonment. When Mirkarimi refused to resign, the mayor suspended him and appointed a temporary replacement, Vicki Hennessy. City Attorney Dennis Herrera crafted the formal complaint and sent it to the city's Ethics Commission and Board of Supervisors, who accepted it and then investigated Mirkarimi under misconduct charges as required by the city Charter.
On August 16, the Commission ruled by 4 to 1 that Mirkarimi committed official misconduct when he falsely imprisoned his wife. Six of the charges brought by the mayor matched District Attorney George Gascón's original criminal charges. Five of those were overruled, including the charge that Mirkarimi dissuaded witnesses and that he abused the power of his office. On October 9, 2012, four of the eleven San Francisco District Supervisors voted against Lee's removal of Mirkarimi as sheriff. The mayor would have needed the votes of nine Board members to remove Mirkarimi.