Captain De Silva and Mendis, Sri Lanka's last recognised batsmen, shared an unbeaten partnership of 83 as Sri Lanka, set 348 to win, reached 205 for five at the close.
South Africa seemed on target for an early win to complete a 2-0 series clean sweep when Sri Lanka slumped to 122 for five, with fast bowler Dane Paterson and left-arm spinner Keshav Maharaj taking two wickets each.
But De Silva and Mendis, who both finished on 39 not out, not only blunted the South African bowling attack but kept the score moving at better than four runs an over.
"It takes a lot of patience as the ball gets older and the pitch gets more placid," said Maharaj.
He said the bowlers had deviated from the basics as they tried to break the De Silva-Mendis stand.
"We did go searching a bit. Towards the end we tried a few things to buy a wicket."
It has been a pitch on which the new ball has been a key factor for bowlers. The second new ball is 27 overs away and Maharaj said the focus on Monday would be "old-fashioned" Test cricket.
"We need to zone in on a length, make it difficult for batters to score with the softer ball and hopefully pick up one or two early wickets and get into the lower order.
Earlier, left-arm spinner Prabath Jayasuriya took five for 129 - his tenth five-wicket in Tests but his first outside Sri Lanka, as South Africa were bowled out for 317 in their second innings after resuming on 191 for three.
"It was one of my targets," Jayasuriya said of success on foreign soil. "I was worried that I couldn't take wickets away from home."
He said he had worked with spin bowling coach Piyal Wijetunga and analyst Jehan Mubarakmade to make a technical adjustment after struggling for consistency in the first innings.
Jayasuriya bowled unchanged through the morning as he took three of the five wickets that fell before lunch, bowling into the rough outside the leg stump of right-handed batsmen.
All three of his wickets on Sunday came from batsmen playing at deliveries that pitched outside leg.
Jayasuriya said he was optimistic about the chances of squaring the series.
"The pitch still looks good to bat on. We have a set pair out in the middle. If we can see off the first hour we can pull off a win."
Kagiso Rabada struck early when he trapped Dimuth Karunaratne in the third over of the final innings but South Africa were made to toil for their wickets on a pitch which remained good for batting.