An Oakland police officer was charged Thursday with engaging in prostitution and obstruction of justice, the latest jolt to a department roiled by scandals and the loss of its former chief.

Officer Ryan Walterhouse, 26, had sex with a prostitute on Oct. 1 in a Castro Valley motel and paid her in cash, prosecutors said in court records. He warned her twice last week about undercover prostitution operations, the prosecutors said.

Walterhouse was arrested when he showed up for work Wednesday following a weeks-long investigation that involved surveillance of his home, officials said.

The original tip of possible misconduct came from one of Walterhouse’s rank-and-file colleagues, said Deputy Chief John Lois of the Oakland Police Department. Investigators discovered that some of the alleged criminal activity happened while Walterhouse was on duty, Lois said.

Prosecutors said Walterhouse called and texted a sex worker to warn her about the undercover stings.

“You might want to call it an early night tonight,” he told the unidentified woman during a phone call Oct. 13, according to court records. “You might want to stick to the online thing right now.”

The following day, prosecutors said, he texted the woman when she should stay off the streets. “I”ll let you know when to,” he wrote in the message, according to court records. “Not yet, they still out, probably after 12,” he said in another message.

Walterhouse had befriended the woman over the last half year during his duties as a police officer, Officer Omega Crum wrote in an affidavit. Tipping her off to the stings put other officers in harm’s way, Crum said.

He was booked at 1 a.m. Thursday at the Glenn Dyer Jail in downtown Oakland and bailed out three hours later, said Sgt. Ray Kelly, a spokesman for the Alameda County Sheriff’s Department.

The Alameda County district attorney’s office charged him with two felony counts of conspiracy to obstruct justice and one misdemeanor count of engaging in prostitution.

Walterhouse’s arrest comes weeks after District Attorney Nancy O’Malley filed charges against three current or former Oakland police officers in connection with their dealings with a sexually exploited teenager. Two others will be charged, prosecutors said. They said they are waiting for key reports from the Police Department before charging the pair.

The scandal spread to several Bay Area law enforcement agencies and led to the abrupt departure of Oakland Police Chief Sean Whent in June. Oakland has been without a chief for four months.

At a news conference Thursday, Oakland Mayor Libby Schaaf denounced Walterhouse’s behavior while praising the officer who turned him in.

“It is incredibly disturbing that, in light of what’s happened, any officer could think it’s acceptable to engage in this type of behavior and further sully a department that has worked so hard to rebuild the public trust,” Schaaf said.

She and City Administrator Sabrina Landreth applauded Walterhouse’s colleague for initiating the criminal investigation, deeming it a sign of hope for the embattled department.

“Although the conduct today is disturbing, this demonstrates that the administrative processes we’ve put in place are working,” said Landreth, who has overseen the Police Department since June.

Although Walterhouse’s arrest is not linked to the previous sexual misconduct scandal, some city officials saw it as another illustration of systemic problems in the police force.

“Even if they’re claiming it’s unrelated in the sense that it’s not the same young woman, it’s still related,” said City Councilwoman Rebecca Kaplan. She said the city has helped perpetuate a macho culture in the department by making little effort to recruit more women or to screen out people with misogynistic attitudes.

“I think it’s a mistake to believe that you can hire people with attitudes of disrespect and train them to stop,” she said. “You have to screen for that.”

Walterhouse was a recent hire who graduated from the 170th police academy in October 2014. His class of 35 cadets boosted Oakland’s ranks to 715 officers, the highest number since a crippling round of layoffs in 2010.

When Mayor Jean Quan took office in January 2011 there were only 656 officers working in the Police Department, and the number fell as some retired or transferred to other departments with more resources and higher morale.

By 2013, the city had only 613 rank-and-file police officers, and officials were desperate to beef up the force and bring down the city’s crime rate.

Although Schaaf has continued the effort to hire more officers, she has also expressed concern about recruitment and hiring practices following a recent string of disciplinary cases. Walterhouse and several other officers who were implicated in misconduct scandals this year were hired between 2012 and 2014, right before Schaaf took office.

The city is currently conducting an audit of police recruitment and hiring to look for patterns in the recent misconduct cases.

In a statement released Thursday, the Oakland Police Officers Association distanced itself from Walterhouse.

“This officer’s actions have no place, nor are they condoned in any way by the police officers who work diligently to keep our Oakland community safe,” said Sgt. Barry Donelan, who heads the association.

He went on to describe Walterhouse’s behavior as a “blemish” on the department and an “embarrassment” to the community.

In addition to the city audit, several City Council members are pushing reforms of their own. Councilmen Dan Kalb and Noel Gallo co-authored a November ballot measure for a citizen-led police commission that would have the power to discipline and fire officers. Kaplan is advocating for new recruitment methods to bring more women, LGBT candidates and people of color into the force.

At the news conference Thursday, Landreth and other officials said the department is already making reforms. In recent months, it has hired more background investigators and strengthened its oversight of police cadets as they move through the training process, said Deputy Chief Danielle Outlaw of the Police Department’s Bureau of Services.

The next police academy, which starts Oct. 31, will have a very small class, Outlaw said.

Rachel Swan, Kimberly Veklerov and Michael Bodley are San Francisco Chronicle staff writers. Email: rswan@sfchronicle.com kveklerov@sfchronicle.com, mbodley@sfchronicle.com, Twitter: @rachelswan @kveklerov @michael_bodley