Pakistan 226 and 299 for 8 (Ali 136, Shafiq 55*, Hafeez 52) lead Sri Lanka 337 by 188 runs
Scorecard and ball-by-ball details
Pakistan showed how tough a challenge coming from behind in a Test can prove. Even though they erased the deficit of 111 runs with relative ease, their position in the match was never secure. Even in conditions in which the assistance to bowlers had reduced drastically, the Pakistan batsmen struggled to perform collectively. Azhar Ali's solid, determined century was the glue that held their innings together, but even he, despite having batted over six hours and taken the lead past 150, was not immune against a seemingly harmless delivery that got him out. On a day that began with Pakistan needing to bat positively to set a competitive target, Sri Lanka moved ahead with a good chance of winning the series 2-0, though a test against a strong bowling attack awaits them.
Dilhara Fernando, in and out of the side for the past 12 years and currently on his 17th comeback, bowled quick, varied his lengths, slipped in his split-finger slower balls as well as accurate yorkers. But a couple of unlikely candidates for wicket-taking deliveries broke two fluent partnerships that looked good for more. A full and wide delivery prompted Mohammad Hafeez to chase it after adding 94 with Ali, only to land safely in the hands of the slip fielder. A short and wide delivery that kept a little low produced a slash, and a fatal edge, from Ali after a century-stand with Asad Shafiq, removing the biggest obstacle between Sri Lanka and a chaseable target.
While Fernando delivered against the flow, en route to his 100th Test wicket, left-arm spinner Rangana Herath accounted for Pakistan's two most experienced batsmen, forcing the settled Ali to restrain himself and focus on rebuilding and damage control instead of stepping up the scoring in an effort to level the series.
Herath hardly got any turn until much later in the day, and was often met with batsmen charging out to him, defending, working it around and, in the case of Ali, driving him comfortably through extra cover. Younis Khan tried the same one ball after a 48-run stand with Ali, but failed to get to the pitch of a flat delivery; the ball scraped the thumb and lobbed up before silly point to be taken smartly by an alert Tharanga Paranavitana. Misbah-ul-Haq showed some intent straightaway, attempting a slog-sweep second ball. But when he tried to drive a loopy delivery from Herath, he edged to slip and departed for just 5.
Amid all this, Ali showed a lot of maturity and confidence, having taken the responsibility to anchor the innings. Early in the day, with some movement on offer, he was content leaving deliveries outside off when Nuwan Kulasekara got the odd one to nip away, and adept at playing his preferred inswingers through midwicket and square leg. Extra cover was his favourite area, and he cashed in when allowed the room to free his arms. Kulasekara, Fernando, Mathews and Herath were all punished through that region, even with a deep point in place in the case of the seamers. He was strong down the ground as well, driving Fernando and Thisara Perera for boundaries, but in a hardworking knock, the singles were no less significant. He and Hafeez ran 39 out of 92 this morning in singles, and 40 out of 100 with Shafiq.
Shafiq was impressive in his first innings' 75 in more difficult conditions; he followed it up with another important contribution, and remains key to prolonging Pakistan's innings and stretching their lead on the final day. If Ali's strength was the off side, Shafiq continued to be dominant square of the wicket. He wasn't given the width he got in the first innings, but the straight deliveries were whipped and pulled through square leg and midwicket. With a sound technique and footwork, and the potential to bat long, he and Ali are increasingly showing they can be the future mainstays of Pakistan's middle order. But having lost Ali, and watched Mohammad Sami, Umar Gul and Saeed Ajmal trapped in front in a space of seven overs, he was left battling with an injured Adnan Akmal for company.
The highlights for Pakistan on the fourth day promised much for their Test future, but the team was still behind at stumps.Their big hope, yet again, remains a Junaid Khan-led retaliation.

Siddhartha Talya is a senior sub-editor at ESPNcricinfo