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.
|Braves rally for six runs in the ninth to defeat Marlins|
|MLS Review: Red Bulls upstage Atlanta thanks to Wright-Phillips brace|
|Warriors breeze past Rockets in game three|
|We have a quality squad – Man City chairman hints at caution in transfer market|
|Wise cruises to maiden PGA Tour victory at Byron Nelson|
|Matic: United can fight for Premier League and Champions League with experience|
|Golden Knights GM on Stanley Cup Finals berth: I don´t know how we did it|
|I did a ´s*** job´ defending LeBron James – Morris|
|Dembele suffers sprained right ankle|
|We know Fellaini´s not going to renew with United – Mirabelli suggests Milan move|
|Cavs´ Lue not satisfied with just one win|
|They even whistled at Torres – Simeone backs Griezmann|
|I arrived as a boy, I leave as a man – Iniesta in emotional Barcelona farewell|
|Lingard: Wembley loss my worst feeling in football|
|Cahill: Conte uncertainty affecting Chelsea|
|Sarri has run out of time – Napoli chief De Laurentiis|
|Barca boss Valverde salutes departing Iniesta|
|I feel like I´ve been run over by a truck or had 15 pints - Crutchlow|
|Four sent off as Ajaccio win chaotic Le Havre play-off on penalties|
|Sweden win shoot-out to retain world title|
|De Vrij penalty was destiny for Inter - Icardi|
|PSG? Maybe one day - Pogba coy over long-term future at Manchester United|
|Messi wins fifth European Golden Shoe|
|Gattuso calls for more malice at Milan|
|Barcelona 1 Real Sociedad 0: Coutinho stunner lights up Iniesta´s farewell|
|Lazio 2 Inter 3: Spalletti´s men seal Champions League qualification with stunning comeback|
|Royals reach play-offs as Kings XI come up short|
|Nadal sees clearly after Rome rain is gone|
|Double whammy for Zverevs as Mischa bows out in Geneva|
|Atletico Madrid pay fitting tribute to tearful Torres|
|Hull FC claim derby spoils, Dragons off the bottom|
|Buzarnescu battles through as McHale impresses in Nuremberg|
|Neymar an artist who will not need special treatment - new PSG coach Tuchel|
|Atletico Madrid 2 Eibar 2: Torres bows out with a double|
|Napoli 2 Crotone 1: Milik and Callejon condemn visitors to the drop|
|Iniesta starts on Barcelona goodbye but Messi rested|
|Nadal rallies after rain break to dethrone Zverev in Rome|
|AC Milan 5 Fiorentina 1: Cutrone brace secures Europa League group stage spot|
|I think I made a fantastic decision - Garoppolo key to Sherman joining 49ers|
|FIFPro appeals to FIFA over Guerrero World Cup ban|
|Neymar made mistake joining PSG - Rivaldo|
|Simple for Simon as outstanding Yates extends Giro advantage|
|Ulster qualify for Champions Cup as Biggar makes history|
|Neymar tired of rumours and staying at PSG, president Al-Khelaifi claims|
|Beaten Halep calms injury concerns ahead of French Open|
|Van der Vaart´s Midtjylland nightmare set to end|
|It has been a crazy ride - Klopp proud of Liverpool ahead of Champions League showdown|
|Raonic pulls out of French Open|
|Liverpool youngster Alexander-Arnold not overwhelmed by England call-up|
|Torres captains Atletico Madrid on farewell|
|Otaegui claims second European Tour win at Belgian Knockout|
|Green: Warriors play best when we feel threatened|
|Daredevils dump out defending IPL champions Mumbai|
|Fan shows off Monk face tattoo on bottom|
|Bayern Munich chief Hoeness rules out spending spree|
|Fury to take on Albanian Seferi in Manchester next month|
|Mourinho mind games won´t distract from Manchester United´s paused progress|
|My motivation is intact - Ranieri open to offers following Nantes exit|
|Shields would probably have made All Blacks squad - Hansen|
|Willian fuels rift talk by hiding Conte with emojis in cup photo|
|Marquez extends lead at Le Mans as Dovizioso crashes again|
|Top-six mentality a boost to England´s World Cup hopes – Southgate|
|Dominant Svitolina retains in Rome as Halep sustains injury scare|
|I´d play for free! - Fifita desperate for State of Origin call-up|
|Plea satisfied with Nice exit as big changes beckon|
|Boateng open to leaving Bayern for move abroad|
|Napoli slam ´shameful and offensive´ Juventus celebrations|
|Red Star´s open-top bus goes up in flames|
|Klopp rejects Liverpool´s Champions League final underdogs tag|
|Root trusts batting form to ´click´ for England|