On a slower pitch where South African batsmen had found batting a tough job and were bowled out for 162 in 46 overs, Bangladesh batted aggressively to gun down the target within 27.4 overs.The victory also confirmed Bangladesh's 2017 Champions Trophy berth in England.
"This was a much-needed win," Bangladesh captain Mashrafe Mortaza said. "The last eight months we have been playing well, we lost the last four matches but we have come back.
"The bowlers gave us a good platform and the batsmen stepped up. It's a good sign for us before going to the third match."
Soumya and Mahmudullah (50) combined for a 135-run stand, Bangladesh's highest ever partnership against South Africa. They rebuilt the innings from a tottering 24-2 after a Kagiso Rabada (2-45) burst.
Soumya sealed the victory with a six at deep-midwicket where Rabada could only parry it, despite a giant leap, to send the home crowd berserk. That was his only six in an 88 off 79, which also included 13 boundaries.
Rabada and Faf Du Plessis also missed Soumya's catch when the batsman was on 60, because of a miscommunication between them.
Rabada, fresh from a record 6-16, had unsettled the Bangladesh batsmen. He nabbed Tamim (5) with a short-pitched delivery before dismissing Litton Das (17), who counter-attacked in style but couldn't sustain it against a barrage of short balls.
Mahmudullah scored 50 off 64 with six fours before Kyle Abbott (1-22) got him, when Bangladesh was just four runs away from victory.
Bangladesh bowlers had earlier put in a disciplined performance to raise the prospects of levelling the series after losing the first match by eight wickets.
Part time offspinner Nasir Hossain (3-26) and left arm fast bowler Mustafizur Rahamn (3-38) wreaked havoc among the Proteas' batting line up after they decided to bat first.
"Credit to Bangladesh. The key on this wicket is to get in and make it count," South Africa captain Hashim Amla said. "We couldn't do that today.
"We had a chance when they were 20 for 2 but Soumya played well."
Fast bowler Rubel Hossain claimed 2-34 to complement the job of Nasir and Mustafizur.
Faf Du Plessis was the highest scorer for South Africa with 41 while Farhan Behardien scored 36 to help the side move past the 150-run mark.
After the record-breaking series against India, Mustafizur was initially well-marshalled by South Africa but he was at his best again in removing Quinton de Kock (2) early.
The slower nature of the wicket made the batting tough but Du Plessis and Hashim Amla looked comfortable and kept the scoreboard moving with a series of singles and doubles.
Rubel Hossain then made a breakthrough in dismissing Amla on 22 to leave South Africa at 45-2.
Nasir Hossain joined the party and took the wicket of Rilee Rossouw, who after being not out in the last three games including the two T20 matches, finally was out on 4.
Along with Nasir, Mahmudullah also operated tirelessly to chock the scoring rate. However, the biggest blow for the visitors was the dismissal of Du Plessis who enjoyed a good run of form in the series.
He hit three fours in his 41 off 64.
Farhar Behardien plundered the bowlers near the end to score 36 off 44 balls, including two fours and a six. But his initiative was not enough to reach 184 that was South Africa's previous lowest score against Bangladesh at the 2007 World Cup which they lost by 67 runs.
It was only the second time Bangladesh has bowled out South Africa in an ODI since that match.
The deciding match is on Wednesday at Chittagong.
New Zealand beats Bangladesh by 8 wickets in 3rd ODI