Hasan Ali took a career-best 10 wickets in the match as Pakistan blitzed South Africa with the new ball to complete a 95-run victory in the second and final Test in Rawalpindi and claim the series 2-0.
Chasing a target of 370 for victory, which would have been a Test record in Pakistan, South Africa were well placed at 241-3 after lunch on the fifth day following a century from Aiden Markram (108).
But they crumbled against the new ball, losing their final seven wickets for 34 runs as Hasan (5-60) and Shaheen Afridi (4-51) ripped through the Proteas' middle and lower order.
Hasan finished with match figures of 10-114 in the match for Pakistan, who won the first Test in Karachi by seven wickets.
Despite the defeat, South Africa would be especially pleased with Markram's performance. He scored his fifth Test century - his first since March 2018 as well as the first in the subcontinent - to keep hopes of an unlikely upset win alive. Markram and Bavuma, who scored 61, shared a fourth-wicket stand of 106 runs and looked comfortable at the crease against the old ball. But neither could negotiate the fresh ball on a surface that was keeping low, and their dismissals opened up the lower order and allowed Pakistan to seal the series 41 minutes before tea on the final day.
South Africa have now lost four of their last five series and ten of their last 13 Tests and are going to have an extended break from the longest format with no games scheduled for the rest of the summer following Australia's decision to postpone indefinitely a proposed series in March.
South Africa had hoped to use this season's Tests to identify a suitable long-term Test captain after Faf du Plessis stepped down last year. Quinton de Kock, who took over in a temporary capacity, is expected to be relieved from the role after managing just 74 runs in four Tests as captain.