Kevin O'Brien scored Ireland's first Test century to bolster hopes of at least avoiding defeat in their debut in the five-day game against Pakistan.
Ireland resumed day four on 64-0 in their second innings having been forced to follow-on by the visitors, who reduced the hosts to 157-6 to seemingly put them in position for an emphatic victory.
Mohammad Amir, having been troubled by a knee injury on day three, looked back to fitness and form on Monday and did much of the damage with figures of 3-57.
But Amir and the rest of the Pakistan attack were frustrated by the brilliance of O'Brien, who forged a pivotal partnership of 114 with Stuart Thompson (53) and an unbroken one of 48 with Tyrone Kane (8), staying unbeaten on 118 to guide Ireland to 319-7 at the close on an historic day at Malahide.
Ireland therefore lead by 139 going into the final day, with a draw and even a victory still within their grasp after being applauded off the field by Pakistan at stumps following O'Brien's magnificent effort.
Opener Ed Joyce (43) was run out by Faheem Ashraf before Andy Balbirnie went for a duck five balls later as Ireland made a dreadful start to the day.
The prospect of defeat loomed ever larger after Amir dismissed any doubts over his ability to produce pace by sending Niall O'Brien's (18) off and middle stumps careering out of the ground, before then claiming the scalp of captain William Porterfield (32).
O'Brien's arrival at the crease prompted the first signs of Ireland resistance but wickets continued to tumble around him until Thompson joined him in the middle.
Their defiance ensured Ireland would not only avoid an innings defeat but also give their own attack something to bowl at in Pakistan's second innings.
And, though a ripper from Shadab Khan removed Thompson, O'Brien proved immovable, his belligerent strokes keeping the scoreboard ticking before he wrote his name in the history books by sneaking two through point to bring up his hundred.
O'Brien and Kane withstood pressure from Amir, Rahat Ali and Mohammad Abbas late in the day, and Ireland go into the last three sessions with the unexpected dilemma of deciding how long to bat before attempting to bowl Pakistan out to seal a seismic shock win.
|Storm and Raiders snatch dramatic wins|
|Boateng desperate for ´best in the world´ Neuer to play|
|Great players have to play here - Real Madrid´s Marcelo continues Neymar courtship|
|Salah can win Ballon d´Or with Champions League triumph, says Luiz|
|Roland Garros wins ´exactly the same´ for Nadal regardless of Federer involvement|
|Rebels romp past Sunwolves, Crusaders retain top spot|
|Halep ´stronger mentally´ as she seeks first grand slam title|
|Cipriani on bench for Baa Baas clash|
|Ronaldo´s rival Salah shifts focus back to Liverpool versus Real Madrid|
|Two arrested in Kiev after clashes before Champions League final|
|Johnny Nelson leads tributes after death of Brendan Ingle|
|Batshuayi puts off Chelsea plans until after World Cup|
|Devon Smith back in Windies squad, Hamilton earns maiden call-up|
|Thiago hints at uncertain Bayern Munich future|
|Dhananjaya pulls out of Windies tour following death of father|
|I feel great - Kerr keeps faith with Warriors on the brink|
|Ronaldo: I can´t be compared with Salah|
|Buffon agent backs Paris Saint-Germain move|
|ICC confirms smart watches prohibited|
|Real Madrid v Liverpool: Champions League final in Opta numbers|
|Mane sends 300 Liverpool shirts to Senegal village for Champions League final|
|Arthur will not join Barcelona before December, Gremio insist|
|Real Madrid v Liverpool: Key battles in the Champions League final|
|Trout hits 15th HR, Bundy strikes out 14|
|Rockets star Paul dealing with hamstring injury|
|Does he only care about his hair? - Denmark coach Hareide slams Pogba, France|
|Rockets push Warriors to brink of elimination|
|World number 84 Kicker suspended for match-fixing|
|WATCH: Paul shimmies in Curry´s face|
|Copa Libertadores Review: Estudiantes into last 16 after thrilling win over Nacional|
|Ronaldo: Cristiano and Neymar would be good together at Madrid|
|Rockets honour Santa Fe victims, first responders at game five|
|Real Madrid rejected €150m offers for Asensio – agent|
|Marshall, Baldwin react strongly to Trump´s comments on NFL anthem stance|
|Nabura handed six-week ban for wild kick|
|Pedroia to return for Red Sox on Friday|
|Warriors´ Iguodala ruled out for game five against Rockets|
|Na leads as Spieth makes solid start at Colonial|
|James Harden, LeBron James headline 2017-18 All-NBA first team|
|Manchester United target Fred to decide future after World Cup|
|´Incredible´ Salah is like Messi, says Ronaldo|
|Salah a big candidate for Ballon d´Or - Muller|
|Message from coach keeping Masters champion Reed grounded|
|Anybody can really win it - Seles feels French Open is wide open this year|
|Mambo number 5! - Non-league star channels Lou Bega hit|
|Pakistan to stop wearing smart watches after ICC intervention - Hasan|
|Saha hails ´great man´ Ferguson as legendary Man Utd boss continues recovery|
|Emery´s depth of knowledge impressed Arsenal´s Gazidis|
|Conceicao extends Porto contract|
|Lomax impresses as Saints overrun Tigers|
|McIlroy in contention at Wentworth as Bjerregaard sets the early pace|
|Bad light calls time on Thiem, Wawrinka out in Geneva|
|Garitano in, Canales out at Real Sociedad|
|Caparros accepts new role at Sevilla|
|Pliskova downed by Larsson after drawing Serena in Paris|
|They´re using the anthem as fake patriotism - Warriors coach Kerr critical of NFL|
|Lyon win record fifth Women´s Champions League title|
|French Open 2018: Doing the unthinkable - the men most likely to topple Nadal|
|French Open 2018: How can Rafael Nadal be stopped?|
|Steve Smith named as marquee player for Global T20 Canada|
|Can Emre play? Yes he Can... and so can Milner|
|Liverpool working to help fans after flight cancellations|
|Abbas and Hasan torment sorry England|
|Xavi ´thrilled´ to sign two-year Al Sadd extension|
|Holtby extends Hamburg contract despite relegation|
|Nadal begins French Open defence against Dolgopolov|
|Serena drawn to play Pliskova in French Open first round|
|FA condemns assault of match official|
|Bologna confirm Donadoni departure|
|Yates lead halved in Giro d´Italia|