South Africa have won seven of their 11 Tests in the current World Test Championship cycle
First Test, day four of five, Centurion
Pakistan 211 & 237
South Africa 301 & 150-8: Bavuma 40; Abbas 6-54
South Africa won by two wickets
Scorecard
South Africa secured their place in June's World Test Championship final by holding their nerve to beat Pakistan by two wickets on an enthralling fourth day of the first Test in Centurion.
Chasing 148 for victory, the Proteas fell from 96-4 to 99-8, including the loss of three wickets for no runs in four balls.
Pakistan seamer Mohammad Abbas, playing his first Test for more than three years, took 6-54 but the hosts found an unlikely batting hero in number 10 Kagiso Rabada.
He crashed 31 not out from 26 balls in a partnership of 51 with Marco Jansen, who finished 16 not out.
The win keeps South Africa top of the Test Championship table and ensures they will contest the final for the first time and face either Australia or India at Lord's.
Of the victory, captain Temba Bavuma said: "[It was] quite an emotional one.
"It was a good advert for Test cricket, a bit of a rollercoaster. We did it the hard way but are glad we are able to get the result.
"It's a bad day to be a beer, today. We will enjoy the moment."
World Test Championship – who can reach the final?
South Africa had the better of most of the first three days but began the fourth day 27-3 with their hopes in the balance.
Experienced pair Bavuma and Aiden Markram settled early nerves until Abbas bowled Markram for 37 for his first wicket of the fourth day.
Abbas, with his immaculate lines and lengths, bowled throughout the 30.3 overs of play either side of lunch on a lively pitch.
The Proteas' innings hit real strife after Bavuma was given caught behind off the seamer for 40, although replays suggested the ball flicked his pocket rather than bat, potentially saving the South Africa skipper had he chosen to review.
Naseem Shah then bowled Kyle Verreynne for two and Abbas had David Bedingham and Corbin Bosch caught behind in the next over.
At that stage South Africa needed a further 49 with two wickets left as Rabada joined all-rounder Jansen.
First the pair reached lunch at 116-8, calming some of the drama. Afterwards Rabada played the decisive hand.
The left-hander attacked and crashed four of his five fours after the break.
It swung the momentum back to South Africa and when Jansen steered the winning runs behind point there were scenes of jubilation in the stands and obvious emotion among the players.
"There wasn't much conversation," said Bavuma, asked about the situation at lunch. "I was still sulking in the toilet. I came out when we needed about 15 runs. It was a tough one."
South Africa are top of the Test Championship table having won seven of their 11 matches.
They began this cycle with a drawn series at home against India but were then beaten 2-0 away in New Zealand.
They sent a weakened side for that series against the Black Caps – a decision that drew some criticism with first-choice players instead kept in South Africa to play in their domestic T20 competition.
Since then, and with their key players returned, they have drawn one Test and won the next six in a row.
Their fixtures have been kind – away series in West Indies, New Zealand and Bangladesh plus Sri Lanka and Pakistan travelling to South Africa after India – but a victory for a side outside the sport's big three of India, Australia and England should be celebrated.
"It is a big one, not just for myself but the team and the coach as well," Bavuma said.
"We have always said we weren't given much of a chance.
"As a team we have overcome a lot. We haven't been super dominant or ruthless but have always found a way."
Notifications, social media and more with BBC Sport
Premier League: Man City 1-0 up at Leicester, Wolves leading at Tottenham
Rabada sends SA into Test final with thrilling win
Australia rally after Bumrah genius on riveting day
The greatest artworks were born of war and bloodshed
Drama documentary of artists Michelangelo, Leonardo and Raphael competing to craft beauty from chaos
A houseparty mixtape for Kiell Smith-Bynoe!
Providing the perfect selections to take the party from the start right till the end
How many more ghosts are in residence?
Sam and Jay have plenty of mysteries to unravel regarding their ghoulish housemates
Dissecting funny and fascinating medicine
Comedian Kiri Pritchard-McLean and guests celebrate medicine’s past, present and future
'Brilliant' Bumrah removes Head & Marsh in same over. Video
The best sports photos of 2024 – and how they were captured
Awesome passes & stunning catches – NFL best plays. Video
Wins, drama and race debuts – take the 2024 F1 quiz
Best shots of Lyon & Boland's key last-wicket stand. Video
Where are all the English managers?
'What has he done?!' – Pant out after scoop attempt. Video
Salah, De Bruyne, Wood – who can discuss a free transfer in January
Mud, sweat & touchdowns – UK's grassroots gridiron
'We want to be first' – Arteta wants more after win over Ipswich. Video
Winning 'never enough' – what we learn in Ferguson documentary
Test your knowledge in the big sports quiz of 2024
'Modern-day gladiator' – the rise of heavyweight hope Itauma
Slam success & ranking rises – how British tennis thrived in 2024
Take on our BBC Gameshows ultimate football quiz
Death of the terrace – one fan's love letter
When Ferguson brought Ronaldo to tears. Video
Brilliant Taylor & 'otherworldly' Burrow star in NFL best plays. Video
How Salah's stats rank among Premier League greats
How heavyweight division is shaping up – and fights we want to see
© 2024 BBC. The BBC is not responsible for the content of external sites. Read about our approach to external linking.