An undercover California highway patrol officer who had infiltrated protests against police violence in Oakland pulled a gun on demonstrators after his and his partner’s cover was blown.

According to accounts in the San Francisco Chronicle and the Berkeley Daily Planet, a few dozen protesters remaining from larger demonstrations yelled that two men in plainclothes were police.

“Just as we turned up 27th Street, the crowd started yelling at these two guys, saying they were undercover cops,” the Chronicle’s freelance photographer Michael Short told the newspaper on Thursday.

The Berkeley Daily Planet reported that the two men tried to walk away, but the couple of dozen remaining protesters “persisted, screaming at the two undercover cops”. The Planet said that an officer “pushed a protester aside”. The demonstrator allegedly pushed back and was tackled and handcuffed.

“Somebody snatched a hat off the shorter guy’s head and he was fumbling around for it. A guy ran up behind him, knocked him down on the ground. That guy jumped backed up and chased after him and tackled him and the crowd began surging on them,” Short said.

He told the Chronicle that the officer pulled a small baton out, then a gun, after the crowd started “surging” them. The Planet reported that more officers quickly moved in to disperse demonstrators.

In a stunning admission, the patrol’s Golden Gate Division told the San Francisco Chronicle that officers had been dressing like and walking with protesters since the first demonstration on 24 November, attempting to gather intelligence to stop highway shutdowns.

Protesters have flooded the streets of the San Francisco Bay area for weeks, since grand juries in New York and Missouri refused to indict police officers for shooting unarmed black men. Many protests have shut down highways, and some in Berkeley have turned violent, resulting in fires and looting.