There was no immediate indication anyone had been hit by the gunfire.
The shooting occurred shortly after 1 p.m. following a report of a gang member spotted in the parking lot of the courthouse, located at 39439 Paseo Padre Parkway, Fremont police Sgt. Chris Mazzone said.
As officers arrived at the courthouse to investigate the report of the gang member, they saw two groups of people driving away in a gray Toyota and black Honda.
The occupants of the cars exchanged gunfire near the corner of Capitol Avenue and Liberty Street while fleeing, Mazzone said.
Police are searching known gang locations in the city for those involved, he said.