As officers responded, a policeman was injured by an accidental, self-inflicted gunshot wound to the leg, the San Diego Police Department said in a statement.
There were no immediate reports of anyone else being hurt. Witnesses said they heard four or five shots coming from a parking structure near the finish line of the San Diego Rock 'n' Roll Marathon, according to the local CBS and NBC television affiliates.
"There's no longer a threat to the community. The scene is secure. The Rock and Roll Marathon has resumed," police said in a tweet.
The marathon, which draws thousands of runners, was winding down at the time. After a brief halt, runners were allowed to complete the race.
Several streets were also closed briefly.
"We had a number of officers working in the area for the Rock 'n' Roll Marathon, and the route was just a couple of blocks to the north from the incident," police chief David Nisleit said in a statement.
Police first received calls about an active shooter around 10:51 am (1751 GMT).
"As officers were responding, one officer fired two rounds at the suspect, but did not hit her," Nisleit added.
"We also had an officer have an accidental discharge of his firearm and he shot himself in his leg he has been transported to the hospital and is expected to make a full recovery."
She was promptly taken into custody.
- 'Safe' to proceed -
"The situation involving an active shooter who was engaged with law enforcement was not related to today's race," marathon organizers said in a statement.
"By 11:45 am, the course was shut down and approximately 4,900 athletes were rerouted into a designated safe zone.
"While the race was officially stopped, law enforcement gave the clearance at 11:56 am for runners to resume their progress toward the finish line and the post-race finish area, where they were able to meet up with family and friends."
There was no immediate information on the shooter's identity or possible motives. But the incident brought back memories of the 2013 Boston Marathon, when two homemade bombs left by brothers Dzhokhar and Tamerlan Tsarnaev killed three people and injured many others.
San Diego, a city of 1.4 million, lies on the Pacific Coast about 190 kilometers south of Los Angeles and on the border with Mexico.
The city's baseball team, the San Diego Padres, said it had been in "close contact" with police following the incident.
"SDPD has confirmed that it is safe for us to proceed with today's Little League parade, as well as our 3:10 pm game at Petco Park," the team said on Twitter.
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections. Election results will be out on May 23.