South Africa's bid to avoid World Cup elimination got off to a nervy start as they reached 92 for two after 20 overs in pursuit of 309 to beat Pakistan at Lord's on Sunday.
For just the second time in their history South Africa will fail to reach the World Cup knockout stages if they lose to fellow strugglers Pakistan.
That unpalatable prospect was looming large after Pakistan piled on 308-7 in their 50 overs.
Proteas skipper Faf du Plessis was leading their desperate charge for survival on 41 not out, while Aiden Makram was unbeaten on one.
Bangladesh's 322-3 against the West Indies was the only successful chase of more than 250 in this World Cup, while South Africa have scored over 300 just once in the tournament.
South Africa's task was made all the more difficult when veteran Hashim Amla was trapped lbw by Mohammad Amir for two after a successful review in the second over.
De Kock was dropped on nought by Wahab Riaz and Du Plessis also survived, from a far harder chance, when his drive was put down by the diving Shadab Khan when he was on 18.
Amir was keeping South Africa in check with a superb spell of aggressive, accurate pace bowling and the Proteas managed only 38 from the first 10 overs.
Du Plessis and De Kock had put on 87 for the second wicket before De Kock was caught by Imam-ul-Haq off the bowling of Shadab Khan.
Earlier, Haris Sohail boosted Pakistan's own slender hopes of reaching the semi-finals with a blistering 89.
Sohail was making just his second appearance at this year's World Cup and his dashing display suggested he should have been involved more often.
The 30-year-old, dropped following Pakistan's opener against the West Indies, made up for lost time as he demolished South Africa's beleaguered bowlers.
Hitting nine fours and three sixes in his 59-ball blitz, Sohail gave Pakistan a shot of adrenaline after Babar Azam's more sedate 69 laid the foundations.
Beaten by bitter rivals India in their last match, Pakistan's players spent the past week involved in a series of spats with frustrated fans both in person and on social media.
After Pakistan captain Sarfaraz Ahmed won the toss and decided to bat first, Fakhar Zaman and Imam-ul-Haq lifted morale with a stand of 81 for the first wicket.
Leg-spinner Imran Tahir then struck twice, having Zaman caught in the slips by Amla on 44 before taking a sublime catch off his own bowling to dismiss Imam, also for 44.
Tahir's 39th World Cup scalp made him South Africa's all-time leading wicket-taker in the tournament.
Sohail blazed away to restore Pakistan's momentum and Babar went past 50 before being caught by Lungi Ngidi on the boundary off Andile Phehlukwayo to end an 80-ball innings.
Sohail smashed a four to reach his 50 in 38 balls and saw Pakistan through to the last over before mistiming a pull off Ngidi.