De Kock returned to the team on Saturday after apologizing, and removed his cap and took a knee alongside all the other players on the field ahead of the start. He made 12 opening the batting.
"It's quite hard to put everything that's happened over the last couple of days behind us," South Africa captain Temba Bavuma said. "There was a bit of it at the back of the mind but we had a job to do and we had to dig deep.
"I was a bit tense but I had confidence in David. He's got one of the most beautiful swings, like a golf swing."
Miller's swinging sixes off the second and third balls of Lahiru Kumara's final over flew into the stands in Sharjah, and settled it after South Africa needed 15 off the last six balls. Tailender Rabada played his role, too, with a six in the penultimate over and the winning runs from an edge past the wicketkeeper for four. He finished with 13 from seven balls.
"It was enough to defend for Lahiru," Sri Lanka captain Dasun Shanaka said of the last over. "Credit to South Africa's batsmen, they finished really well.
"It's really hard for us after this game," he added, with Sri Lanka now in a battle to claim one of the two semifinal places from the group.
Spinner Tabraiz Shamsi and seamer Dwaine Pretorius both took 3-17 after South Africa put Shanaka's team in to bat. But Sri Lanka's 142 all out in 20 overs, set up by opener Pathum Nissanka's brilliant 72 from 58 balls, was highly competitive.
It seemed like a winning total when legspinner Hasaranga removed Bavuma (46) and Pretorius in consecutive balls in the 18th over, having removed Aiden Markram off the final ball of his previous spell.
South Africa needed 22 from nine balls when Rabada kicked off the late rally with his six back down the ground.
ENGLAND MAKE IT EASY
Jos Buttler was near his brutal best as England thrashed old rival Australia by eight wickets with 50 balls to spare.
Buttler smashed 71 not out from 32 balls with five thumping sixes as England's batters quickly finished off what its bowlers had started by knocking the Aussies over for 125.
Openers Buttler and Jason Roy put on a rapid 66 to start England's chase. Jonny Bairstow was with Buttler to finish it off, and also didn't hang around by launching two sixes in his 16 not out from 11 balls.
England's bowlers, with Chris Jordan leading with 3-17, tore through Australia at the start, with the Australians slumping to 21-4 in 6.1 overs. Australia rallied to see out its full 20 overs, but only just with Mitchell Starc the last man out off the final ball of the innings.
The result put England top of Group 1 outright and underlined its status as one of the favorites for the title, having lost the final of the last T20 World Cup in 2016 to West Indies.
Australia, which belied its shaky recent form by winning its opening two games, is tied with South Africa for second place in Group 1 but behind the South Africans on run rate after Saturday's hammering by England.
The top two from the group will reach the semifinals.