A cop was shot and a woman was taken into custody after gunfire broke out near a California marathon Sunday, according to reports.

The woman, who is in her 50s but has not been identified, was allegedly firing an airsoft gun in the air and putting the weapon to her own head on the eighth floor of a parking garage at First Avenue and C Street, according to KSWB-TV.

Police fired several shots at her and missed, but one cop accidentally shot himself in the leg.

The incident was three blocks from the route of the San Diego Rock ‘n’ Roll Marathon, which was winding down at the time.

Organizers halted the race for 10 minutes while police dealt with the deranged woman.

Roughly 4,900 runners had to be redirected and several streets were closed, officials said.

The situation began at about 10:50 a.m. with police responding to a call of a hit-and-run, Sgt. Tom Sullivan told the San Diego Union-Tribune.

Gunfire, now believed to have come from the cops, was reported at 11:20 a.m.

“She pointed a gun at one of the officers,” said Police Chief David Nisleit, according to TV news station KNSD.

One officer fired two rounds but missed the woman, the outlet reported.

Police had the woman in custody by 12:30 p.m.

“There’s no longer a threat to the community,” the San Diego Police Department tweeted at the time. “The scene is secure. The Rock and Roll Marathon has resumed.”

The injured officer is expected to make a full recovery.

With Post wires