A Cambridge police officer shot himself in the leg when his gun accidentally went off outside police headquarters, police said.

The officer is being treated for a leg wound after the shooting, which took place about 12:18 p.m. at the headquarters on 6th Street, according to a police statement.

The officer, a veteran of the force who was not identified, was seen being carried out of the station on a stretcher to a waiting ambulance.

The officer is in good condition at a hospital, police spokesman Jeremy Warnick told NBC10 Boston.

It wasn't immediately clear to police what caused the gun to fire. The officer was heading to the station when it happened, Warnick said.

A portion of the street in front of the station was closed for about an hour as investigators searched for clues.

"We have officers that are outside the station processing the scene still. We'll be looking to speak with him once he receives the treatment at the hospital," Warnick said.