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.
18. Juli 2018
|Sarri wants new central midfielder and hints at Chelsea stay for Cahill|
|Nantes sign former Manchester United full-back Fabio|
|Marcelino rewarded with one-year Valencia extension|
|Warburton retires: Bale leads social media tributes to Welsh great|
|Mistakes do not define me, says Chelsea boss Sarri|
|Saints and Tigers to honour Horne with Twickenham clash|
|I want to keep Hazard, says Sarri|
|Europe must stop American juggernaut at Carnoustie|
|Joshua planning for heavyweight ´legacy´ – starting with Povetkin|
|Warburton retires: Wales and Lions star´s career in numbers|
|Matching ´ridiculous´ Tiger not on McIlroy´s radar|
|Spain sent me World Cup SOS, claims Benitez|
|Ozil, Gundogan critics should ´shut up´ - Klopp|
|McIlroy plans to play carefree at Carnoustie|
|Pakistan thrash Zimbabwe to secure series win|
|Warburton retires: Gatland salutes Wales and Lions great|
|Sturridge determined to stay at Liverpool|
|Mbappe is an alien – Varane|
|Warburton retires from rugby|
|India to assess Bhuvneshwar as Bumrah makes Test squad|
|Injured Craddock passes $100,000 in donations at Tour de France|
|WATCH: Perez taunts team-mate after audacious training goal|
|Alison Becker tweets ´I´m joining Liverpool´... but all is not as it seems|
|F1 Raceweek: Hamilton chasing down Schumacher - German GP in numbers|
|Notorious Carnoustie holds fond memories for legendary Watson|
|Rooney refused to be ´dead weight´ at Everton|
|The Open 2018: Molinari, Rahm and the in-form contenders at Carnoustie|
|Marsh interested in Australia leadership roles|
|United can challenge City for Premier League title, says Rooney|
|MLB All-Star 2018: Seven things you missed at Midsummer Classic|
|American League win home run-filled MLB All-Star game|
|Dragons lure Sims from Broncos|
|Cassano: Ronaldo like Nadal, Messi like Federer|
|Lakers´ Ball undergoes successful knee surgery|
|´We kill them, Messi or no Messi´ - Pogba´s pre-Argentina World Cup speech revealed|
|Cardinals suspend GM Keim for five weeks after DUI|
|Dalic: I can coach Brazil or Barca but Croatia my favourite|
|Warriors coach Kerr extends contract|
|I´m ready to bust him up - Miller calls out Joshua after New York confrontation|
|CAF Champions League Review: ES Tunis and TP Mazembe set the pace|
|Mixed day for seeds in Newport as Muller progresses|
|Rams sign Cooks to five-year extension|
|Cowboys’ Randy Gregory reinstated by NFL|
|Verdasco survives Swedish Open scare as Paire is picked off in Umag|
17. Juli 2018
|US Open announces record prize fund for 2018|
|Stosur wins battle of former grand slam champions in Gstaad|
|Emery is Arsenal´s best signing, says Pires|
|Brewster commits to Liverpool with long-term deal|
|Panama boss Gomez steps down after World Cup|
|No Chelsea agreement for Golovin, claims CSKA president|
|Root looks right at home as England ease to series victory|
|Brighton sign Mali midfielder Bissouma from Lille|
|Kaka backs Brazil boss Tite after ´excellent´ World Cup|
|Alaphilippe the toast in France as Van Avermaet increases Tour lead|
|Shkupi 0 Rangers 0: Gerrard´s men advance despite dour draw|
|Khazri ends Sunderland nightmare as Saint Etienne swoop|
|The Open 2018 diary: Rose lets Rio go as Rahm goes ´Lefty´|
|Lampard raids Chelsea and Liverpool in Derby double swoop|
|Balotelli returns to Nice training after Marseille talks stall|
|Owens wants to play in the CFL, says agent|
|I don´t like thinking too much - Johnson|
|Toulon president fined as French club receive suspended points penalty|
|Top of the flops - Mickelson plays exquisite trick shot over man´s head!|
|Kerber targeted Wimbledon after 2017 disappointment|
|England´s World Cup heroes given dedicated parking spots|
|Insigne prefers Messi to new Juve star Ronaldo|
|Koepka enjoys playing with a chip on the shoulder|
|Ryan Hall to leave Leeds Rhinos amid reports of NRL move|
|Hamann slams Lahm for Low criticism|
|Hart named in Manchester City squad for United States tour|