Sri Lanka started the day three runs behind the West Indies and finished an imposing 279 ahead after a last-gasp stand by century-maker Dhananjaya de Silva and No. 10 batsman Lasith Embuldeniya in the second Test on Thursday.
Their unbeaten 107-run partnership tore the momentum from the West Indies on day four and put back in charge the home side, which leads the two-test series 1-0.
Sri Lanka was 221-8 in its second innings and leading by only 172 when Embuldeniya joined de Silva, who was on 80 and facing a new ball only three overs old.
But they got to tea, and kept on going, frustrating the tourists to still be there at stumps on 328-8.
De Silva reached his eighth test century and at the close was 153 not out from 259 deliveries. He's hit 11 boundaries and two sixes.
Embuldeniya, working just as hard in support, was 25 not out after 110 balls in his 14th test. His only hit over the rope, a six back over the head of spinner Roston Chase, brought up their century stand in the day's second-to-last over.
De Silva was also involved in important partnerships of 78 runs for the fourth wicket with Pathum Nissanka, and 51 for the sixth with Ramesh Mendis.
Nissanka's second half-century of the match ended on the last ball before lunch, lbw for 66 off 154 deliveries. He made 73 in the first innings.
Sri Lanka resumed on 46-2 and went to lunch at 151-4, leading by 102 runs.
The West Indies seized the initiative when Dinesh Chandimal was caught and bowled by Chase for 2, Mendis was caught in the deep off captain Kraigg Brathwaite, Suranga Lakmal was trapped for 7, and an injured Angelo Mathews batted at No. 9 and edged to the slips on 1.
But de Silva and Embuldeniya wrestled the advantage back and appear to have made a draw safe, and put the series victory in hand.
Veerasammy Permaul had the best bowling figures of 3-100 off 39 overs, and Chase had 2-82 off 27 overs.