Pakistan's Azhar Ali smashed a second century in successive matches on Wednesday to leave the final Test against Sri Lanka poised for an intriguing finish.
Azhar made 136 as Pakistan wriggled out of a corner to post 299-8 in their second innings by stumps on the fourth day in Pallekele, a lead of 188 runs with two wickets in hand.
The tourists now have three sessions on the fifth day to conjure a series-levelling win on a wearing pitch that will offer some turn to prolific off-spinner Saeed Ajmal.
But Sri Lanka remain favourites to win or draw the match and clinch their first series victory in three years since beating New Zealand at home in 2009.
The hosts won the first Test in Galle by 209 runs before the second in Colombo was drawn.
Sri Lanka's South African coach Graham Ford conceded it was hard to predict how the Test will end.
"The way it has swayed back and forth over the four days, I don't think anyone can say what will happen tomorrow," said Ford.
"The game is still pretty much even. Pakistan has a very good attack but we too will be confident of doing well on the last day. This is what makes Test cricket so exciting."
Azhar, who made 157 in the Colombo Test, held the innings together for six hours, hitting 13 boundaries in his fourth Test century and the third this year.
The 27-year-old put on 94 for the second wicket with his overnight partner Mohammad Hafeez and 48 for the third with Younis Khan after Pakistan resumed the day at 27-1.
But the most crucial partnership came towards the end of the day when Asad Shafiq (55 not out) helped Azhar add 100 for the fifth wicket after Younis and skipper Misbah-ul Haq had departed quickly.
Fast bowler Dilhara Fernando and left-arm spinner Rangana Herath sparked a lower order collapse in the final hour as Pakistan slipped from a comfortable 276-4 to 299-8.
Fernando had Azhar caught behind and then claimed his 100th Test wicket by trapping Mohammad Sami leg-before.
Herath claimed Umar Gul and Saeed Ajmal leg-before, but Shafiq saw out the day for Pakistan in the company of Adnan Akmal, who batted despite a hairline fracture in his left hand.
"It was disappointing to get out because Asad and myself had decided to see out the day," said Azhar. "But I am happy to get another century. I have batted well this year and want to make good use of my form."
Azhar did not rule out a Pakistan win on Thursday. "We have the bowlers to do the job for us," he said. "I think the total we have is good enough to defend.
"The wicket has slowed down, but there is still something in it for the bowlers."
Hafeez, who also hit a century in Colombo, made 52 when he was dismissed just before lunch with Pakistan two runs away from wiping out the first innings deficit of 111 runs.
The Pakistan vice-captain edged a wild drive off Fernando to Tharanga Paranavitana in the slips.
Pakistan went to lunch at 119-2, in front by eight runs, after Younis had given his team the lead by tapping Angelo Mathews for a single to point.
Herath dismissed both Younis and Misbah and ended the day with 4-64. Fernando finished with 3-65.
Scoreboard at stumps:
Pakistan 1st innings: 226 (Asad Shafiq 75, T. Perera 4-63, R. Herath 3-40)
Sri Lanka 1st innings: 337 (T. Paranavitana 75, T. Samaraweera 73, T. Perera 75, Junaid Khan 5-70, Saeed Ajmal 3-66).
Pakistan 2nd innings (overnight 27-1):
Mohammad Hafeez c Paranavitana b Fernando 52
Taufeeq Umar lbw b Kulasekara 4
Azhar Ali c P. Jayawardene b Fernando 136
Younis Khan c Paranavitana b Herath 19
Misbah-ul Haq c M. Jayawardene b Herath 5
Asad Shafiq not out 55
Mohammad Sami lbw b Fernando 3
Umar Gul lbw b Herath 0
Saeed Ajmal lbw b Herath 5
Adnan Akmal not out 0
Extras: (b6, lb8, w6) 20
Total (for eight wickets, 104 overs) 299
Fall of wickets: 1-16 (Taufeeq), 2-110 (Hafeez), 3-158 (Younis), 4-176 (Misbah), 5-276 (Azhar), 6-280 (Sami), 7-281 (Gul), 8-299 (Ajmal).
Bowling: Kulasekara 22-7-50-1, Perera 17-1-66-0 (w5), Herath 32-4-64-4, Fernando 20-1-65-3 (w1), Mathews 12-0-38-0, Samaraweera 1-0-2-0
Pakistan lead by 188 runs with two wickets in hand.
Toss: Sri Lanka
Umpires: Steve Davis (AUS) and Simon Taufel (AUS)
TV umpire: Ranmore Martinesz (SRI)
Match referee: David Boon (AUS)