An on-duty San Francisco park ranger was stabbed by an enraged motorist Sunday morning in the city’s South of Market neighborhood.

The ranger was in his marked Recreation and Park Department vehicle commuting from Patricia’s Green in Hayes Valley to the Embarcadero when he saw a driver yelling at other motorists near the Seventh Street off-ramp of eastbound Interstate 80 at 7:04 a.m., according to San Francisco police and Recreation and Park Department sources. The ranger followed the suspect vehicle onto the Central Freeway, where the suspect vehicle crashed into the center divider of the connector ramp. The unarmed ranger pulled up to offer assistance, and the man lunged at the ranger with a knife and stabbed him, police said.

Passersby stopped and detained the man while also coming to the aid of the ranger. Their names have not been released. San Francisco police placed the suspect in custody. He was transported to a hospital with undisclosed injuries.

The ranger, who is 30 and has been with Rec and Park for five months, was treated at the scene and released. The suspect was detained and charged with attempted murder, aggravated assault, carjacking and driving a stolen vehicle.

Sam Whiting is a San Francisco Chronicle staff writer. Email: swhiting@sfchronicle.com Twitter: @SamWhitingSF