An undercover police officer, who had been marching with anti-police demonstrators, aims his gun at protesters after some in the crowd attacked him and his partner in Oakland, California December 10, 2014. REUTERS/Noah Berger

After their cover was blown, two plainclothes officers found themselves in a melee with demonstrators and a freelance photographer captured the incident on film

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

Michael Short, a freelance photographer who was covering the protest for the San Francisco Chronicle and witnessed the incident, told the Guardian that after the crowd realised that the pair were undercover officers, they became “incensed”.

One of the protesters snatched the beanie from the head of the smaller of the two officers. Immediately afterwards, another member of the crowd ran up from behind and punched the same officer in the head, knocking him to the ground.

The shorter officer stood up and tackled his assailant, at which point the other officer, who was already brandishing his baton, drew his gun and pointed it at the crowd, which was surging forward.

This is the moment that Short captured on film.

After drawing his weapon, the taller officer radioed for backup. According to Short, between 20 and 25 uniformed officers who had been accompanying the protest arrived and pushed back the crowd. “Everyone was yelling and screaming,” said Short.

Short said that the danger didn’t really register with him in the moment. “In retrospect, yeah, it was scary,” he said. “One little slip and he could have shot anyone in the crowd, including myself.”

The two officers have not yet been named, though the California Highway Patrol’s Golden Gate division has confirmed that there were two plainclothes officers at the protest, and that one of them had drawn his weapon.

Avery Browne, the chief of the Golden Gate division, told a press conference on Thursday that several police agencies had been using, and would continue to use, plainclothes officers. “We will use all of the avenues that we can to keep the public safe,” he said, adding that police were also monitoring protesters on Twitter.

“We know it is upsetting and disturbing any time a firearm is displayed,” Browne said, “[but] we want to prevent someone getting hurt, and last night these guys put their lives on the line because a group of individuals decided to destroy small businesses.” He said the incident would be investigated.

Short said that in the context of the marches as a whole, there have been complaints of heavy-handed response by police; he said he’d witnessed people being hit with batons. Later on the same night, California highway patrol officers fired rubber bullets at protesters from a freeway overpass, one of whom had to be hospitalised.

But he also said he understood the officer’s actions. “I put myself in his shoes. If there were 40 or 50 people screaming at me, and I saw my partner punched in the head, I would be pretty scared, and I would pull out a gun if I had it too.”