A San Francisco police officer suspended four years ago for sending racist and homophobic text messages to other officers pleaded guilty Thursday to robbing two city banks last year, officials said.

Rain Daugherty, 44, pleaded guilty in federal court to two counts of bank robbery as part of a negotiated deal with prosecutors, according the the U.S. Attorney’s Office.

Daugherty was indicted on Jan. 10 for the Nov. 29 robbery at the East West Bank on Irving Street in Sunset District and the Dec. 13 robbery at the Cathay Bank on Clement Street in the Richmond District. In both robberies he handed the teller a note demanding money.

He was arrested on Dec. 18 and faced two bank robbery charges for each incident, according to the U.S. Attorney’s Office. Daugherty agreed to plead guilty to two of the charges in exchange for prosecutors dropping the remaining two charges, officials said.

He is being held in Glenn Dyer Jail in Oakland and is scheduled to be sentenced on May 9. He faces up to 20 years in federal prison for each count.

Before his brief robbery spree late last year, Daugherty was embroiled in a text messaging scandal inside the San Francisco Police Department that came to light in 2015.

The text messages, which disparaged racial minorities, women and gay people, were discovered by federal agents in 2012 during their investigation of Sgt. Ian Furminger, a longtime department plainclothes officer.

Furminger and another officer were convicted in 2014 of stealing money from drug dealers during searches.

Then-San Francisco police Chief Greg Suhr didn’t disclose the text messages until 2015, when he announced he would discipline numerous officers for their role in the scandal.

Suhr originally fired Daugherty, who fought the case and was ultimately suspended without pay. San Francisco police officials did not immediately return messages about Daugherty’s current employment status with the department.

Evan Sernoffsky is a San Francisco Chronicle staff writer. Email: esernoffsky@sfchronicle.com Twitter: @EvanSernoffsky