Chasing a modest 148-run target, Pakistan were on course for victory with Haris Sohail's 50-ball 52 with four boundaries and a six but leg-spinner Wanindu Hasaranga turned the tables with 3-21 to restrict the hosts to 134-6 in 20 overs.
Canada lock Josh Larsen visited the South African changing room after the match to offer his apology and wish the Boks well for the rest of the tournament.
Paris St Germain’s Kylian Mbappe, who has been struggling with a recurring thigh problem, has been replaced in the squad by Borussia Moenchengladbach forward Alassane Plea.
Second seed Roger Federer, who received a first-round bye, broke Ramos-Vinolas twice in the opening set and sailed through his service games without facing a breakpoint in the match.