The hosts, who trailed by 12 runs on the first innings, put on a strong batting performance to move to 177-2 in their second innings by stumps on the third day at the Sinhalese Sports Club.
During the eventful day's play, Pakistan's wicket-keeper Sarfraz Ahmed smashed a maiden Test century and Sri Lanka's spinner Rangana Herath became the first left-arm bowler in history to take nine wickets in an innings.
Jayawardene and his close friend and long-time team-mate Kumar Sangakkara batted together for the last time in a Test match to put on 98 for the unbroken third wicket.
Jayawardene, who was warmly applauded to the crease by Pakistani fielders and some 4,000 home fans, played fluently to strike seven boundaries.
Left-handed Sangakkara was unbeaten on 54, with Sri Lanka 165 runs ahead with eight wickets in hand on a wearing pitch expected to assist spinners on the last two days.
Sri Lanka, who won the first Test in Galle by seven wickets, are hoping to sweep the short series to give Jayawardene, their former captain, a winning farewell.
"We need to continue the same way tomorrow and put up a big score," Sri Lanka's coach Marvan Atapattu said. "There is no target in our mind yet, but we will take stock when the spinners start getting more turn."
Upul Tharanga scored 45 runs in an opening stand of 54 runs with Kaushal Silva before both batsmen were dismissed by left-arm spinner Abdur Rehman in the post-lunch session.
Pakistan seamer Junaid Khan did not take the field in the second innings as he was taken to hospital and kept under observation after complaining of giddiness.
Junaid, who took five wickets in the first innings, had been hit on the helmet by a rising ball from Dhammika Prasad in the morning session.
"Junaid is much better now," said Pakistan's batting coach Grant Flower. "There was no internal bleeding and he is back from hospital.
"We will see how he feels tomorrow morning. But it's too early to say whether he can bowl again in this game."
Earlier, Sarfraz hit a gutsy 103 to carry Pakistan to 332 runs all out by lunch from their overnight score of 244-6 in reply to Sri Lanka's 320.
Sarfraz, who came to bat after tea on the second day with Pakistan struggling at 140-5, led a remarkable fightback by the lower order that enabled the tourists gain the slender lead.
But Herath grabbed attention in the morning session by claiming the four remaining wickets to finish with 9-127, only the second Sri Lankan after Muttiah Muralitharan to take nine wickets in an innings.
The 36-year-old Herath, who surpassed his previous best of seven for 89 against Bangladesh in Colombo last year, is currently the number one Test spinner in the official rankings.
He has claimed 255 wickets so far in 57 Tests.
Starting the day on 66, Sarfraz reached his hundred by hooking left-arm seamer Chanaka Welegedara for a six after pulling the previous delivery for a boundary.
He was ninth out with Pakistan just six runs away from taking the lead when he edged Herath to give wicket-keeper Niroshan Dickwella his fifth catch in the innings.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ