It happened about 4:30 a.m. in the area of Larkin Street and Golden Gate Avenue in the city's Tenderloin District.
Police say the man tried to help another person who was being assaulted by a group of people.
Those people then turned on him. He was stabbed multiple times.
He's now in stable condition at the hospital.
People who live nearby say incidents like this can deter them from helping others.
"A lot of times the innocent person can be the one to get the worst brunt of it," resident Diane White said. "To me, I would just stay out of it and get away from it. But, you know, he was being a Good Samaritan because I guess in his heart he thought he could save somebody, but it's unfortunate he ended up getting the worst end of it."
Police say the attackers also slashed the tires on the man's car.
There are no suspects in custody.