The shooting occurred as students were being let out of school for the day from the June Jordan School for Equity and City Arts and Technology High School, which share a campus, San Francisco Police Officer Carlos Manfredi said.
Three of the victims ran inside the school, and police initially ordered students to stay in place until police searched each room and determined it was not an active shooter situation. A fourth victim hurt in the shooting went to the Bayview Police Station, Manfredi said.
"One female victim has life-threatening injuries to her upper torso," he said.
Four male suspects wearing dark hoodies and jeans were seen running away from the area, Manfredi said.
"This was an isolated incident outside of the school building where one student was being targeted by outsiders," the San Francisco Unified School District said in a statement.
Classes at June Jordan School in the city's Excelsior District will resume Wednesday and extra security and counselors for students will be available, it said.