Like so many classic Western anti-heroes before him, he rolled (literally) into town with a singular goal in mind: cleaning up the streets, which had become a gritty hotbed of harassment, vandalism, break-ins and grift.

The only difference was that he was a slow-moving, 400-pound robot with a penchant for snapping hundreds of photos a minute without people’s permission, and this was San Francisco’s Mission District in 2017.

What could go wrong? Quite a bit, as it turns out.

In the last month, his first on the job, “K-9” — a 5-foot-tall, 3-foot-wide K5 Autonomous Data Machine that can be rented for $6 an hour from Silicon Valley start-up Knightscope — was battered with barbecue sauce, allegedly smeared with feces, covered by a tarp and nearly toppled by an attacker.

As if those incidents weren’t bad enough, K-9 was also accused of discriminating against homeless people who had taken up refuge on the sidewalks he was assigned to patrol. It was those troubling allegations, which went viral last week, that sparked public outrage and prompted K-9’s employers — the San Francisco chapter of the animal rescue group SPCA — to pull the plug on their newly minted robot security pilot program.

“Effective immediately, the San Francisco SPCA has suspended its security robot pilot program,” Jennifer Scarlett, the organization’s president, wrote in a statement emailed to the Washington Post last week. “We piloted the robot program in an effort to improve the security around our campus and to create a safe atmosphere for staff, volunteers, clients and animals. Clearly, it backfired.”

SPCA officials said the robot was rented to patrol the parking lot and sidewalk outside the animal shelter after the building had been broken into twice and employees had become fed up with harassment and catcalls.

The backlash began after an animal shelter spokeswoman, in an interview with the San Francisco Business Times last week, seemed to suggest that the robot was an effective tool for eliminating the homeless encampments outside the SPCA, leading to a sudden reduction in crime. SPCA officials now say they didn’t mean to imply that they wanted to be rid of the homeless and have pointed out that they partner with several local organizations to provide veterinary care for homeless pet owners.

Nevertheless, a public outcry, complete with calls for the robot’s destruction, quickly ensued.

A flurry of headlines implied that the robot was specifically employed to target the homeless.

“Robot wages war on the homeless,” a particularly inflammatory Newsweek headline read.

SPCA officials said, they’ve received hundreds of messages encouraging people to seek retribution against the animal shelter. So far, officials said, the facility has experienced two acts of vandalism.

“The SF SPCA was exploring the use of a robot to prevent additional burglaries at our facility and to deter other crimes that frequently occur on our campus — like car break-ins, harassment, vandalism, and graffiti — not to disrupt homeless people,” Scarlett’s statement said.

“We are a nonprofit that is extremely sensitive to the issues of homelessness,” the statement added.

In a statement, Knightscope referred to accusations that its robot was hired to target homeless people as “sensationalized reports.”

“The SPCA has the right to protect its property, employees and visitors, and Knightscope is dedicated to helping them achieve this goal,” the statement said. “The SPCA has reported fewer car break-ins and overall improved safety and quality of the surrounding area.”

K-9 is not the first Knightscope machine to have a short-lived security career. In July, a K5 robot patrolling Washington Harbour in Washington, D.C., ended up in a fountain, its cone-shaped body halfway submerged.