Sri Lanka reached 45-0 but then lost all 10 wickets for 75 runs to slip to 120 all out, with Kyle Abbott, Aaron Phangiso and Farhaan Behardien each taking two wickets.
Hashim Amla made an unbeaten 56 in a comfortable chase that an AB de Villiers six completed with 14 deliveries to spare.
Both teams had already been eliminated. This was a horrible display from Sri Lanka, who arrived as the defending champions but leave having beaten only Afghanistan.
Without injured captain Angelo Mathews, their middle-order fell apart after openers Tillakaratne Dilshan and Dinesh Chandimal raced to 45 in 28 balls.
Left-arm spinner Phangiso was hit for 10 runs from the first two balls he bowled but, later in the same over, bowled both Chandimal and Lahiru Thirimanne in successive deliveries.
As South Africa, in particular the excellent leg-spin of Imran Tahir, took pace off the ball, Sri Lanka perished to poor shots and sloppy running.
South Africa finish third in Group 1, behind West Indies and England, who play India and New Zealand respectively in the semi-finals.
They may feel unfortunate not to be in the last four – their two defeats both came in the last over of the match – but this was the most comfortable of victories.
Amla was never troubled, occasionally taking boundaries behind square on the off side or wristily whipping through the leg, including one six.
He lost Quinton de Kock to a direct hit from Dilshan and Faf du Plessis to an erroneous lbw, the latter allowing De Villiers to arrive and belt the winning runs off a Suranga Lakmal full toss. (Courtesy BBC Sport)