Kevin O'Brien scored Ireland's first Test century to give the hosts hope of winning their maiden Test against Pakistan in Dublin.
The 34-year-old's milestone came from 186 balls as Ireland - who began day four on 64-0, still 116 runs from making Pakistan bat again, and then slipped to 157-6 - closed on 319-7 for a lead of 139, with O'Brien 118 not out.
Ireland are now dreaming of becoming just the fourth side - after England against Australia in 1894 and 1981 and India against the Baggy Greens in 2001 - to win a Test match having been asked to follow on.
William Porterfield's men had looked in danger of an innings defeat when Mohammad Amir (3-57), showing no effects of the knee problem that caused him to leave the field on Sunday, made Gary Wilson (12) his 100th Test scalp and left the hosts 23 runs behind with only four wickets intact.
However, O'Brien - who blazed the fastest-ever World Cup hundred, off 50 balls, against England in Bengaluru in 2011 - put on 114 with Stuart Thompson (53) for the seventh wicket and then an unbroken 48 with Tyrone Kane (8no off 67), during which time he sealed his century by hitting Amir through point for two.
Amir had removed Kevin's brother Niall (18) and Porterfield (32) in the space of six balls in the first session and then ousted Wilson in the second, while Ed Joyce (43) was run out courtesy of a direct hit from Faheem Ashraf at mid-on.
Andrew Balbirnie, meanwhile, bagged a pair after being pinned lbw by Mohammad Abbas (2-54), who went on to dismiss Paul Stirling (11) in the same fashion as Pakistan moved into a commanding position at Malahide.
But O'Brien and Thompson dug in and while Thompson was unable to press on after reaching fifty - bowled by a delivery from Shadab Khan (1-63) that pitched outside off and turned back sharply to strike middle - O'Brien continued to give Ireland a chance of a winning start to Test cricket.
Will Ireland pull off a stunning win? Find out by watching day five in Dublin from 10.50am on Tuesday on Sky Sports Cricket.