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.
|Composed Woods hits turn with five-shot lead|
|Chiefs´ Mahomes has another record-breaking Sunday|
|Saints QB Drew Brees passes Brett Favre for most career completions|
|Emery hints Leno may need patience after Cech display|
|Picamoles scores four as Montpellier batter 14-man Toulouse|
|Messi breaks LaLiga record|
|Worcester fend off prowling Tigers, Sarries go top|
|AC Milan 2 Atalanta 2: Last-gasp Rigoni rescues a point|
|Neymar keen to repay supporter affection|
|Pellegrini rues West Ham´s wastefulness|
|Paris Saint-Germain´s positive response buoys Tuchel|
|Lewis rekindles fond memories with Vilamoura triumph|
|Arsenal 2 Everton 0: Lacazette, Aubameyang extend winning streak|
|Stephens suffers as Osaka withdraws in Wuhan|
|Rhinos run riot to secure Super League status|
|Risk brings reward for victorious Marquez|
|Let´s have some fun - Wentz tweets message to Eagles fans ahead of return|
|Maybe in a year Chelsea will be at Liverpool´s level – Sarri|
|Under-pressure Rodgers bemoans ´bitty´ Celtic start|
|Slater should be banned for Grand Final - Fittler|
|Simon ends Bachinger fairytale to lift Metz title|
|Dominant Thiem reigns in St. Petersburg|
|Neymar hands young fan his shirt during Paris Saint-Germain victory|
|Quick-Step Floors storm to fourth time trial gold|
|Jorginho sets new passing record in West Ham draw|
|Rubiales slams ´crazy´ LaLiga schedule|
|Rennes 1 Paris Saint-Germain 3: Tuchel´s Ligue 1 record stays perfect|
|Why so serious? Joshua reveals Fury has blocked him on Twitter|
|West Ham 0 Chelsea 0: Sarri´s 100 per cent start comes to frustrating end|
|Marvellous Marquez reigns in Aragon yet again|
|Real Madrid will not go to the USA with LaLiga - Perez|
|Erasmus adds five players to Springboks squad|
|Barcelona snub ´hardest decision´ of Griezmann´s career|
|Perez pays tribute to Ronaldo and Zidane|
|Cazorla concedes Arsenal lacked self-belief under Wenger|
|Get King Kong for AJ! Joshua understands critics´ demands|
|Korea change sees Bertens take title in Seoul|
|I love Bilic, but I let him down – Arnautovic|
|He will never fight me! Fury hits out at ´ponderous´ Joshua|
|Azpilicueta convinced Hazard can be ´the best´|
|Wigglesworth´s career in Opta numbers as he breaks Premiership record|
|Ronaldo has nothing to prove, says Allegri|
|Federer shines as Europe hold narrow lead at Laver Cup|
|Astros, Yankees and Indians record dramatic wins|
|Pliskova too strong for Osaka in Tokyo final|
|Kyle Busch comes from behind to win again in Virginia|
|Dybala can play as a striker – Allegri|
|Pochettino never doubts ´special´ Kane|
|NASCAR results at Richmond: Kyle Busch comes from behind to win again in Virginia|
|McIlroy just worried about himself at Tour Championship|
|MLS Review: Atlanta stay clear of Red Bulls|
|Rose reminds everyone Woods has been here before|
|Cronk in doubt for Grand Final due to ´severe´ shoulder injury|
|Timberwolves sign Towns to extension|
|Hearn wants Wilder for Joshua, not ´un-entertaining´ Fury|
|Woods pleased with putting consistency|
|Ballon d´Or not a focus for Asensio|
|Man City star Mendy revels in Joshua triumph|
|Braves clinch first NL East title since 2013|
|I want Wilder, says Joshua|
|Inter must live on the edge to win, says jubilant Spalletti|
|Woods leads by three at Tour Championship|
|Bordeaux end Clermont´s perfect start, Zebo at double in Racing win|
|Lopetegui not worried about Courtois footwork|
|Joshua finds emphatic answer to Povetkin challenge|
|BREAKING NEWS: Brutal Joshua knocks out Povetkin in seventh round|
|Real Madrid can´t win 5-0 every week - Varane|
|Al Ahly 4 Horoya 0 (4-0 agg): Egyptian giants reach CAF Champions League semi-finals|
|Kings upset Warriors, Leinster batter Edinburgh|
|Son committed to Tottenham amid Bayern links|