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.
|Lenglet: No problem with Dembele at Barca|
|Townsend rings the changes for Springboks clash|
|Claudio Ranieri´s managerial career in Opta numbers|
|Mahmudullah´s first century in eight years boosts Bangladesh|
|Fellaini gets the chop ahead of 31st birthday|
|Maradona: Solari will not last at Real Madrid|
|Molinari: Race to Dubai success would not surpass Ryder Cup glory with Fleetwood|
|Dortmund star Sancho was a Bayern target, confirms Salihamidzic|
|Gerrard enjoying ´buzz´ of management|
|Hamilton questions approach to Formula One expansion|
|Ranieri honoured to lead ´exceptional´ Fulham squad|
|Solari saw Isco out of shape - Ceballos|
|Ranieri replaces Jokanovic at Fulham|
|Durant keeps details of Green spat ´in-house´ but envisages resolution|
|Rooney: Kane and Sterling are England superstars|
|Messi will make Argentina return, says Maradona|
|Warriors drop Hawks as Green serves suspension|
|In-form Healy sends Australia into semis|
|Former NBA star McGrady says Carmelo Anthony should retire|
|Celtics´ Smart: We have to look at ourselves in the mirror|
|Federer plays down preferential treatment talk|
|Mourinho is better than Guardiola – Maradona|
|Mbappe plays down Pele comparisons|
|Don´t worry bro – Mendy responds to Trump|
|Melvin, Snitker win manager of the year awards|
|Warriors´ Green suspended for Hawks clash|
|Asensio: It´s not for me to lead Madrid|
|Rooney ready to enjoy England farewell after pressure of ´Golden Generation´|
|Ludwigsburg stun high-flying Murcia in BCL|
|Rams v Chiefs moved to LA due to Mexico City field conditions|
|Skriniar discussing new Inter contract, confirms agent|
|Former Barcelona boss Martino named MLS Coach of the Year|
|Bell fails to report to Steelers, will sit out rest of season|
|Federer back on track after dismal Thiem display|
|Udinese appoint Nicola after sacking Velazquez|
|Monaco deny they broke rules regarding youth recruitment|
|Del Bosque, Zidane, Lopetegui - The former Castilla coaches Solari follows into Real Madrid hot seat|
|Ozil rejected ´crazy offers´ from Asia, reveals agent|
|Real Madrid appoint Solari on permanent basis|
|LeVert avoids need for surgery, should return this season|
|Neuer confident despite concerns over Bayern Munich form|
|All I ever wanted to do is win, says Sixers signing Butler|
|Pogba: Coming home to United was the best feeling ever|
|Watson among four signing new Bath deals|
|Susanna Dinnage to replace Scudamore as Premier League chief executive|
|Murray commits to Brighton until 2020|
|Rooney rejected chance of pre-World Cup farewell|
|Impressive Anderson thrashes Nishikori|
|Ozil´s Germany absence a ´pity´, says Sane|
|Rooney: I´ll finish my career in the US|
|McIlroy unsure of 2019 European Tour membership|
|Australian Open dismisses concerns of Federer scheduling bias|
|Hue Jackson joins Bengals staff as ´special assistant´|
|Real Madrid confirm Reguilon injury|
|Higuain handed two-match ban for Juve meltdown|
|Kruis ruled out for England as Jones calls up uncapped quartet|
|A year on from Italy failure, Ventura leaves Chievo after four games|
|Bairstow misses out as unchanged England promote Stokes|
|Recalled Alba denies Luis Enrique bust-up|
|´Unhappy´ Christensen won´t push for Chelsea exit|
|Nadal to make Abu Dhabi comeback in December|
|Taijul helps Bangladesh tighten their grip despite Taylor ton|
|Neymar joining Real Madrid wouldn´t hurt Iniesta|
|It´s just team spirit - Livingston not worried by Durant-Green exchange|
|Trippier out of England squad with groin injury|
|Ex-Sri Lanka international Lokuhettige charged by ICC|
|Former England and Chelsea star Joe Cole retires|
|Nets offer support to LeVert following serious leg injury|
|Panenka proud Sergio Ramos imitates his penalties|
|Liverpool´s Alisson seeks patience to reach potential|