The tourists went to tea on the fourth day at 209-3 in their second knock, still needing 379 to avoid an innings defeat in the first match of the two-Test series.
Stand-in captain Ashwell Prince was unbeaten on 17 and A.B. de Villiers was on nine at the break on Sunday.
Makeshift openers Jacques Rudolph and Andrew Hall put on 165, South Africa's best ever for the first wicket against Sri Lanka, when Fernando struck 35 minutes after lunch.
The tall bowler, playing on his home Sinhalese sports club ground, forced a well-set Rudolph to edge a catch to Chamara Kapugedera at third slip and then trapped new man Hashim Amla leg-before.
Prolific spinner Muttiah Muralitharan ended Hall's defiance by claiming him leg-before just before tea as South Africa lost three wickets in the afternoon session in the space of 20 runs.
Left-handed Rudolph, a late inclusion in the touring team after captain Graeme Smith suffered an ankle injury, made a fluent 90 with 13 boundaries.
Hall, who opened the innings in place of the indisposed Herschelle Gibbs, batted for more than four hours to score 64 when he fell to Muralitharan's guile.
Gibbs, who did not field on Saturday due to a stomach bug, is fully recovered but can bat only after the fall of the fifth wicket.
South Africa, trailing by 587 runs on the first innings, need to bat out the remaining four sessions to force a draw.
Rudolph and Hall, who resumed at the overnight score of 43-0, batted through the morning session to take South Africa to 150 without loss by lunch.
They surpassed South Africa's previous first-wicket record against Sri Lanka of 137 by Kepler Wessels and Andrew Hudson at the same venue in 1993.
Sri Lanka scored 756-5 declared in their first innings with captain Mahela Jayawardene making the fourth highest Test score of 374 after sharing a world record partnership of 624 with Kumar Sangakkara (287).
The batting feast came after South Africa were dismissed for 169 on the opening day.