David Miller and Kagiso Rabada blasted South Africa to a dramatic four-wicket T20 World Cup win over Sri Lanka after Wanindu Hasaranga took a hat-trick at Sharjah Cricket Stadium.

The Proteas welcomed Quinton de Kock back into the side after he missed the win over West Indies on Tuesday following Cricket South Africa's decision that all Proteas players must take a knee prior to the remainder of their games in the tournament.

De Kock took the knee on Saturday in a united stance against racism before Sri Lanka were bowled out for 142 from their 20 overs in a Group 1 contest neither side could really afford to lose.

Pathum Nissanka made 72 off 58 balls, with the brilliant Tabraiz Shamsi and Dwaine Pretorius taking 3-17, while Anrich Nortje also impressed with figures of 2-27.

A fourth-wicket stand of 47 between captain Temba Bavuma (46) and Aiden Markram made it advantage South Africa, but Hasaranga (3-20) gave Sri Lanka the upper hand.

The spinner bowled Markram with the final ball of the 15th over and returned to dismiss Bavuma and Dwaine Pretorius at the start of the 18th – reducing the Proteas to 112-6 and completing his hat-trick.

South Africa needed 15 to win off the final over from Lahiru Kumara after Rabada had dispatched Dushmantha Chameera for a huge six and they got home with a ball to spare after Miller launched two maximums into the leg side.

The Proteas are on four points with two wins from three matches, while Sri Lanka are unlikely to qualify following their second loss.

Shamsi shows why he's number one

Shamsi showed how he has become the top-ranked T20 bowler in the world, dismissing Bhanuka Rajapaksa and Avishka Fernando caught and bowled as Sri Lanka lost wickets far too frequently.

The spinner, who has the most T20I wickets this year with 32 at an average of 13.62, bowled 13 dot balls and only conceded one boundary, also getting Hasaranga caught in the deep.

Pretorius and Nortje bowled superbly at the death, with only Nissanka ensuring Sri Lanka were able to make a significant total after clearing the rope three times and hitting six fours.

Miller time after Hasaranga heroics

The Proteas were in trouble on 26-2 after Chameera trapped Reeza Hendricks lbw before taking a catch off his own bowling to remove De Kock (12)

Bavuma led the recovery with a composed knock, but the craft of Hasaranga swung the game in Sri Lanka's favour.

Rabada flexed his muscles with a huge six off the penultimate over and struck a four to win over the powerful Miller middled two full deliveries from Kumara out of the ground.