Chandimal (85) and Dhananjaya (79) led a spirited recovery from 54-3 as they equalled their country’s record fourth-wicket stand of 131 against South Africa and laid the foundations for a total of 340-6 at stumps.
But Sri Lanka are waiting to learn whether they will be without Dhananjaya for the rest of the match after the all-rounder pulled up with an apparent thigh strain and was forced to retire hurt.
South Africa seamer Wiaan Mulder, recalled for the first time since his first Test appearance – also against Sri Lanka, almost two years ago – bowled his side back into contention with two quick wickets in the final session.
Having won the toss and chosen to bat, Sri Lanka captain Dimuth Karunaratne oversaw a brisk start to his side’s innings, rattling up four boundaries in his knock of 22 from 20 balls.
Although the skipper chopped on a Lungi Ngidi delivery that came back into him, that did nothing to slow the run-rate, with Kusal Perera (16) and Kusal Mendis (12) raising the 50 inside the ninth over.
They were soon pegged back by the Proteas’ change bowlers as Mendis miscued a pull shot off Anrich Nortje to mid-on before Mulder struck in his first over, with Perera caught behind slashing outside off stump.
However, the fourth-wicket pair batted sensibly to take Sri Lanka to lunch, with Dhananjaya outscoring the dogged Chandimal as he moved on to his half-century in the afternoon with a sweetly-struck cover boundary off Mulder.
Dhananjaya looked keen to accelerate, surviving a leg before appeal against Keshav Maharaj on umpire’s call and celebrating his escape by hitting the spinner’s next ball over the top for the first six of the innings.
A century seemed on the cards – but, having pushed Lutho Sipamla for a straightforward single on the off side, Dhananjaya pulled up as he reached the non-striker’s end, wincing in pain, and had to be helped from the field.
Niroshan Dickwella, who replaced his stricken team-mate at the crease, made an uncertain start by edging Sipamla through the slips, but soon settled into his groove to help Chandimal build another big partnership of 99.
It was Mulder (3-68) who finally eased South Africa’s frustration, producing a ball that rose sharply on Chandimal, took the shoulder of the bat and looped up for Faf du Plessis to take the slip catch.
Suddenly the home side sensed another breakthrough and Mulder provided it once more, rapping Dickwella (49) straight and low on the pads for an lbw decision that was upheld on review.