South Africa scored 7-128 in 19 overs in reply to India's 6-124 to level the four-match series at 1-1 in a dramatic finish on Sunday after their top order were undone by India spinner Varun Chakravarthy, who took a career-best 5-17.
Stubbs and Coetzee chased down a 40-run target in three overs of swashbuckling hitting at the death to rescue the result when it looked as if India would pull off an unlikely victory.
The visitors had been put in to bat and struggled to deal with South Africa's seamers, losing wickets cheaply before Hardik Pandya's unbeaten 39 gave them a respectable total to try to defend.
India opener Sanju Samson, who scored a sparkling century as the tourists beat South Africa by 61 runs in Durban on Friday, was bowled by Marco Jansen three balls into Sunday's contest, while Abhishek Sharma and captain Suryakumar Yadav also departed early.
Tilak Varma (20) and Axar Patel (27) made valuable contributions to India's total.
South Africa's top order were undone by a masterful display from Varun, whose googly bamboozled the home batsmen.
He castled Aiden Markram (3), Reeza Hendricks (24) and Marco Jansen (7) before having the dangerous Heinrich Klaasen, who sliced a full delivery, caught by Rinku Singh at long-off.
Varun's next ball deceived David Miller, bowled first ball, to reduce South Africa to 6-66.
When Coetzee joined Stubbs at the crease at 7-86, they set about pulling the hosts out of a desperate situation.
"Fortunately the run rate never got away from us," said Stubbs.
"I had 30 in mind to get off the last three, and the dew came in to help us also. He came in and said, 'We can win this'. The crowd was behind us and it was amazing."
Fast bowler Coetzee showed the way with 19 off nine balls in a display of lusty hitting that turned the momentum of the contest while Stubbs saw South Africa to victory with successive fours to finish with 47 off 41 balls.
"Of course in a T20 game you don't want to get 120, but I was proud of the way we bowled," said Yadav.
The next meeting will be in Pretoria on Wednesday.