Dhananjaya de Silva completed a century before Sri Lanka declared their second innings on 360-8 to hand Pakistan a mammoth victory target of 508 in the second Test on Wednesday.
Vice-captain De Silva hit 109 and put on 82 runs for the eighth wicket with Ramesh Mendis, who was unbeaten on 45, after the hosts resumed day four on 176-5 in Galle.
De Silva was run out at the non-striker's end and skipper Dimuth Karunaratne called his batsmen back in the second session of play.
The West Indies hold the record for the highest-ever successful Test chase of 418 against Australia in 2003 at Antigua.
De Silva put on a key stand of 126 with overnight partner Karunaratne, a left-handed batsman who battled back pain during his knock of 61.
De Silva, who began the day on 27, reached his ninth Test hundred with a cracking boundary off Mohammad Nawaz and raised his bat to the applauding dressing room.
Karunaratne fell in the first session after he escaped two close calls, which were unsuccessfully reviewed by Pakistan, off Nauman Ali's left-arm spin.
Nauman finally got Karunaratne, caught at short leg, where Abdullah Shafique took a sharp reflex catch.
Karunaratne, who had back spasms and did not field in the Pakistan innings, got help from the physio during his two hours and 45 minutes at the crease as he went past 6,000 Test runs.
Sri Lanka fought back from 117-5 in their effort to bounce back from their opening loss in the two-match series.
Pakistan fell behind Sri Lanka by 147 runs after being bowled out for 231 in response to the hosts' first-innings 378.
Pakistan's highest chase came in 2015, when they made a target of 377 in Pallekele. The tourists chased down a Galle record of 342 in the opener of this series.