Officers responded to a crash near 20th and Folsom streets connected to a shooting at the Valencia Gardens housing project around 7:30 p.m.
Police said an initial investigation revealed that the male suspect confronted a group of people at the Valencia Gardens housing project at Guerrero and Rosa Parks Lane, pulled out a gun and fired shots at the group.
Someone in the group fired back at the suspect and he was struck in the stomach. His car was also struck by gunfire, police said.
The suspect drove away and was spotted at 17th and Folsom streets running stoplights by University of California at San Francisco police. The UCSF officers chased him until he crashed into another car at 20th and Folsom streets.
The suspect attempted to flee from the scene of the crash on foot but officers detained him in the 700 block of Treat Avenue and took him into custody, police said.
He was taken to San Francisco General Hospital and his condition was not immediately known.
The driver of the other vehicle involved in the crash was also taken to the hospital and treated for complaint of pain to his neck. His injuries are not considered life threatening, police said.
Police recovered a gun from the suspect at the crash site. Another gun was recovered at Valencia Gardens.