Dean Elgar's 127 guided South Africa to a first-innings lead of 145 runs despite a maiden five-wicket haul for Vishwa Fernando, before Dimuth Karunaratne fought to 91* to take Sri Lanka to a lead of five runs by stumps.
Elgar and Rassie van der Dussen had added 118 runs together on the first evening, and they resumed their partnership with confidence. It wasn't until the 15th over of the morning session that Sri Lanka finally got a wicket, by which point the stand was worth 184 runs – the highest second-wicket partnership in Tests between the two sides.
As happened in Sri Lanka's first innings, a wicket before lunch brought a collapse, and after Elgar edged Dushmantha Chameera to slip in the first over after drinks, Van der Dussen followed him back to the changing room an over later, caught off the glove from the bowling of Dasun Shanaka.
Shanaka struck again to remove Faf du Plessis via a thin edge, before Vishwa Fernando had Quinton de Kock caught in the slips for his first wicket of the innings.
Wiaan Mulder and Temba Bavuma saw the hosts through to lunch, but the former was trapped leg before to his first ball after the break as Vishwa picked up his second.
Debutant Asitha Fernando then struck, removing Keshav Maharaj via yet another edge through to the wicket-keeper. Bavuma fought his way to 19 before misjudging an inswinger from Vishwa, padding up to a ball which was crashing into the stumps.
Anrich Nortje scored a breezy 16-ball 13 before giving another catch to the slips, before Lutho Sipamla and Lungi Ngidi threatened to put together a frustrating final-wicket stand. Their 19-run partnership was nonetheless eventful, with Sipamla scoring his first Test runs via a cover-driven four, while Ngidi reached double figures for the first time in Tests.
Vishwa completed his maiden Test five-for when he had Sipamla caught at gully off the back foot, leaving South Africa all out for 302 and a lead of 145 runs for the hosts. The left-armer seamer finished with figures of 5/101.
#DidYouKnow, only one bowler has ever taken a hat-trick for 🇿🇦 in Tests!— ICC (@ICC) January 4, 2021
Lungi Ngidi couldn't quite complete the feat today, but in the 1960 Lord's Test, Geoff Griffin dismissed England's Mike Smith, Peter Walker and Fred Trueman with consecutive deliveries 🎩 pic.twitter.com/YEXMyowEfn
Sri Lanka's second innings got off to a disasterous start for the visitors when Kusal Perera, who top scored in their first innings, was bowled by Ngidi with just one run on the board. But Dimuth Karunaratne provided a captain's knock, battling through against testing bowling.
Lahiru Thirimanne kept him company for some time, notching up 31 runs before Ngidi returned and provided the breakthrough with a leg-side strangle. Kusal Mendis was dismissed in the same fashion to Ngidi's next ball, though the 24-year-old wasn't able to complete a hat-trick as Minod Bhanuka let the next delivery go through to the wicket-keeper.
Bhanuka didn't last long though, with the pace of Nortje earning a tough chance which was well taken by Keshav Maharaj. But through it all Karunaratne remained firm, and Niroshan Dickwella proved an able partner with the duo's partnership unbroken at the close having added 41 runs and taken Sri Lanka to a slender lead.
Personalise your homepage with an ICC account
News, fixtures and updates tailored to your favourite team. Never miss a moment!