A failed carjacking in South San Francisco ended early Sunday with the suspect dead after an off-duty police officer was stabbed, then shot the suspect, who then stole a police car and led police on a chase before being shot again after ramming a police car and wielding a knife at officers, police said.

The suspect died in a medical center parking lot, according to Sgt. Ken Chetcuti of the South San Francisco Police Department. The off-duty San Francisco officer and the carjacking victim were hospitalized and are expected to recover. South San Francisco and Daly City police and the San Mateo County District Attorney’s Office are investigating the incident, including the officer-involved shootings.

The incident began at about 5:35 a.m. Sunday when police responded to calls reporting a fight outside a gas station at 110 Hickey Blvd. in South San Francisco, Chetcuti said. Officers found two men fighting after one had allegedly attempted to carjack his car and another.

The suspect allegedly stabbed one of his intended victims, then used the knife to stab an off-duty San Francisco police officer who witnessed the incident and tried to intervene. The off-duty officer shot the suspect in self-defense, according to police.

South San Francisco police tried to subdue the suspect, who continued to fight despite having been shot. They used stun guns on him twice, but he continued to resist. The suspect then climbed into a South San Francisco police car and fled. Police chased him as he sped into Daly City, where he tried to enter the gates of the Kaiser medical center on Hickey Boulevard. He rammed an approaching police car and abandoned the stolen police car. He wielded the knife at police, and was shot again by officers, police said.

No South San Francisco officers were injured in the incident. The names of the suspect and the officers involved in the shootings have not yet been released.

Anyone with information is asked to call the South San Francisco Police Department at 650-877-8900 or the anonymous tip line at 650-952-2244.

Michael Cabanatuan is a San Francisco Chronicle staff writer. Email: mcabanatuan@sfchronicle.com Twitter: @ctuan