There were moments in the third ODI that bore the hallmarks of a classic South Africa meltdown, but after the match the captain AB de Villiers lauded his side's strength under pressure, as they withstood a Thisara Perera onslaught to defeat Sri Lanka by 56 runs.

South Africa had almost sewn the match up after 32 overs, having reduced Sri Lanka to 94 for 7, with 130 more to get at 7.22 an over. But having traveled at less than three runs an over until then, Robin Peterson's seventh then disappeared for 35, as Perera blasted five sixes and a four to revive Sri Lanka's chances.

Lonwabo Tsotsobe then fluffed the simplest of chances off Perera in the 39th over, which might have set more panic upon the fielding side, but Faf du Plessis held his nerve under a high ball off Perera's blade three overs later, to effectively secure the match.

"It's a great win. We handled the pressure situations extremely well, which pleased me very much," de Villiers said. "Robbie [Peterson] went for a big over when I threw him into the deep end. But it's the way the boys reacted which is what made me really proud after that. We stayed really calm, stuck to our game plans, kept it really simple and came out on top. The guys looked really hungry today and I'm glad we made it through.

"After Lopsy [Tsotsobe] dropped the catch I told him it could happen to anyone, because I felt he might get another catch, which he did. He improved the second time around. Those kinds of things happen. Sometimes it costs you the game, sometimes it doesn't. This time we were lucky it didn't cost us the game. We moved on, which was the positive thing again. We stayed calm in all the situations and that was great."

The victory was largely engineered by David Miller, who struck a career-high 85 not out from 72 balls, to elevate South Africa to 223 for 7. The visitors appeared headed for a modest score below 200 as late as the 48th over, but a Miller blitz off the final two overs, when he bludgeoned 35 from 12 balls, set what was a challenging target on an uncharacteristically dry Pallekele surface. At the time Miller was in the company of Ryan McLaren, with whom he added 69 for the eighth wicket.

"When AB went and Robbie got out, I just said to Ryan we really need to hang in here until the last three overs," Miller said. "We were looking at 45 overs the whole time and if either Ryan or myself had got out, it's Morne Morkel and Tsotsobe coming in, so we thought let's really take it as deep as we can. We just decided the last two overs would be key.

"The wicket was very slow and had a lot of turn. We really had to work hard up front and try and build partnerships and take a little bit longer than normal. This innings means a lot to me."

Tsotsobe's best-ever haul of 4 for 22 also had a major bearing on the result, as he removed Sri Lanka's top three in his first four overs, before returning to dismiss Angelo Mathews in the middle overs. His figures were all the more remarkable because he had not been selected for the second ODI, after being unavailable for the first through injury, but de Villiers was quick to praise the efforts of Morkel, who was unlucky to finish wicketless, having bowled a menacing first spell of four overs that conceded only six.

"After missing the first two games and having to prove his form and condition, Lopsy coming back like that, and showing his skill that's in him was really pleasing for me," de Villiers said. "The partnership he and Morne formed up front was outstanding and they set the standard for us. Lopsy picked up the wickets so congrats to him for that, but you've got to give credit to Morne as well. He hit the deck really hard and stuck to his lengths. He didn't give them much to hit and to score off."

South Africa also produced their best all-round fielding performance of the series - despite Tsotsobe's drop - after having fielded particularly poorly in the first match in Colombo. Sri Lanka only made 24 in the mandatory 10-over Powerplay, thanks in no small part to the visitors' consummate ground fielding.

"We saved about 20 runs in the field I believe. Fielding is an attitude and it's a hunger to win the game. If you have that, you'll always have a good fielding set-up. I thought we had that tonight. We can still improve, but I'd like us to do that more consistently."

Andrew Fidel Fernando is ESPNcricinfo's Sri Lanka correspondent. He tweets here