Striker Chris Iwelumo scored a last-minute winner for Charlton, who played for almost an hour with 10 men after Jose Vitor Semedo was sent off.
In only the 36th minute, Semedo picked up his second booking following a foul on Viafara and they the visitors soon found themselves under pressure.
But Saints could not break through and Bradley Wright-Phillips wasted their best chance when he headed wide.
And Iwelumo made them pay when nodded home Luke Varney's cross on 90 minutes.
Southampton boss George Burley: "I'm gutted to concede a goal at the end like that but then I cannot say we deserved to get anything out of this game. We never pressured Charlton and I do not know why.
"We have scored loads of goals all season and when things were not working for us I brought on substitutes but nothing happened.
"I'm blaming no one for the goal. Credit to their substitute Varney. It was a great ball of his into the box and there was not much we could do about it."
Charlton manager Alan Pardew: "Of all the matches in my managerial career this win has got to be in my top five.
"This was a massive win for us after the three defeats. To go down to 10 men and then go and score the winner in front of your own fans in the last minute does not come any better than that.
"I felt we looked like a team today. The sending off knocked us back a bit but we gave a performance which will have done us a power of good."
Bristol City were made to fight all the way by Southampton before moving back to second place in the Championship.
City were 2-0 up on 17 minutes, thanks to Darren Byfield's close-range finish and Ivan Sproule's left-footed strike.
Southampton got back into the game nine minutes into the second half when Jamie McAllister put through his own net.
The visitors dominated the remainder of the match but they had Youssef Safri sent off for violent conduct in injury time and City held on for victory.
Bristol City boss Gary Johnson: "It was the proverbial game of two halves. We showed quality in the first period and our spirit in the second.
"We will keep our feet on the ground and still consider that we go into every Championship game as underdogs.
"But this group of players have now proved over a number of games that they are comfortable at this level and we'll do our best to maintain standards."
Southampton boss George Burley on Safri's red card: "When a fellow professional gets another sent off it is always disappointing.
"Their lad went down as though as he had been poleaxed, even though Youssef barely tapped him.
"We totally dominated the second half and camped in City's half without getting the break we needed."
Southampton are currently mid-table in the Championship
Southampton FC has confirmed that London-based hedge fund Sisu Capital has made an offer to buy the club.
A deal would see Sisu taking a majority stake in parent company Southampton Leisure Holdings plc of at least 55%.
Southampton said the investment would be a "long-term commitment" and that Sisu would boost the club's prospects for promotion to the Premier League.
It also said that Microsoft tycoon Paul Allen had not made a "formal" bid for the club.
Southampton Leisure Holdings, which controls the club, announced earlier in the week that it was in talks with an unnamed "major UK-based investment company".
It said on Thursday that subject to approval by the board and the company's shareholders, the deal would be executed by means of a placing of new shares at 40p per share - 20% below its current share price.
This means the investment values Southampton Football Club below its market value on the London Stock Exchange.
Winning investment?
If the deal goes ahead, Sisu has pledged to support the continuing development of the club's youth academy and to strengthen its first-team squad in an effort to secure the club's long-term future.
Southampton was in the top flight for 27 years before being relegated in 2005 and has struggled to regain its footing since then.
If Sisu succeeds in taking a majority stake in the company, it would be the first time a British football club has been controlled by a hedge fund.
The bid shows that investor interest for football clubs in the UK is not slowing, with Arsenal most recently in the spotlight, as Russian billionaire Alisher Usmanov shows growing interest in taking control of the Premier League club.
John is mobbed by delighted team-mates after his winner
Stern John's early strike proved enough for a Southampton win over Cardiff.
Striker John fired home with his left foot on 15 minutes after Inigo Idiakez had played a delightful ball between two Cardiff defenders.
Cardiff's dominance continued after the break, but Robbie Fowler and Stephen McPhail shot wide from good positions.
A frantic finish saw Saints' Jason Euell blasting over on 88 minutes with the goal gaping, and Peter Wittingham firing wide for Cardiff in injury time.
Southampton manager George Burley: "We did not play particularly well, and we never really looked comfortable.
"There were a few performances that were not great, but we defended well, and that is something we have not done all season. We have played a lot better and lost, but it is important to keep clean sheets.
"We are strong in all areas of the pitch, but the defence has been a real problem since the start of the season."
Cardiff manager Dave Jones: "We have to keep clean sheets - it's as simple as that. We're always chasing the game.
"It's frustrating because we've totally dominated a game that we really should have gone on to win.
"We gave a bad goal away and then Southampton defended for their lives. I just hope we could get our noses in front for once."