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.
|Liverpool´s strikeforce reminds Ronaldo of Real Madrid|
|Hysaj staying at Napoli ´regardless of Sarri´s future´|
|Amir fully fit for Lord´s Test|
|A fast start to life - The Golden Knights and the expansion teams who excelled early|
|Molina gets two-year anti-doping ban for positive test after Joshua bout|
|Ramos: We´re a vintage Real Madrid team|
|Klopp key to controlling Liverpool emotions, says Alonso|
|Bjorn names Westwood, Harrington, Donald and McDowell as Europe vice-captains|
|Scarlets players left wounded by ´shocking´ Scotstoun pitch|
|Arsenal fined £20,000 for Leicester penalty protest|
|Storm offer Bellamy ´significant´ deal amid reported Broncos interest|
|Rashford writes moving tribute on anniversary of Manchester Arena attack|
|Heaton backs Kane´s captaincy credentials|
|Salah deserves Ballon d´Or if Liverpool win Champions League – Owen|
|Wasps flanker Willis out for up to a year|
|Real Madrid v Liverpool: Is the Champions League enough to save Zidane?|
|I was left out on reputation - Nainggolan angered by World Cup snub|
|Pellegrini targets Europe with West Ham|
|Lopetegui extends Spain contract|
|Edinburgh-bound Barclay´s Scarlets career over following Achilles surgery|
|Saints swoop for NRL star Naiqama|
|Zidane: Be careful when you criticise Ronaldo|
|It doesn´t get better - Stevens relishing best-of-three shootout for Celtics|
|Favre named new Dortmund boss|
|LeBron and Lue hail evergreen Kyle Korver|
|Kane named England captain for World Cup|
|Wright slams Arsenal over Emery: It´s like a sushi shop!|
|Pellegrini named new West Ham manager|
|Late drama and sustained Ronaldo magic - Real Madrid´s road to the Champions League final|
|Yankees´ home runs fuel win over Rangers|
|LeBron scores 44 points as Cavs level series against Celtics|
|Kaufusi re-signs with Melbourne Storm|
|LeBron James sets record for postseason field goals|
|Monchi: Alisson will only leave Roma if I come out of retirement!|
|No offers from Chelsea or Zenit, says Sarri´s agent|
|No Champions League pressure as PSG´s Tuchel calls for patience|
|Nationals´ Juan Soto hits homer in second career at-bat|
|Buffon to decide future in a week amid PSG speculation|
|Eli Apple embarrassed by 2017 antics, ready to move forward|
|Bills release Richie Incognito from reserve/retired list|
|Gentry and Pelicans want Cousins back in New Orleans|
|MLB extends Blue Jays closer Osuna´s administrative leave|
|Lloris, Jedinak and Kjaer ask FIFA to allow Guerrero to play at World Cup|
|Wolfsburg preserve Bundesliga status after play-off win over Kiel|
|Zidane was my idol and always will be - Wijnaldum|
|Liverpool ready to fly out of the blocks in Kiev - Henderson|
|Montreal Impact 0 LA Galaxy 1: Ibrahimovic sent off for slapping opponent|
|Real Madrid v Liverpool: Salah, Ronaldo lead the line in combined XI|
|Bertens keeps hat-trick hopes alive in Nuremberg|
|Monfils and Mannarino fail to fly the flag in Lyon|
|Morata, Fabregas, Herrera and more in Spain´s World Cup rejects XI|
|Reina to face FIGC hearing|
|Emery set to be appointed by Arsenal - reports|
|LeBron ´appreciative´ of hometown effort to put up statue of him|
|Cazorla leaves Arsenal after injury nightmare|
|Derby´s Rowett seeks permission for Stoke talks|
|Messi physically and mentally ready for the World Cup, Sampaoli proclaims|
|Murray expected to return at Rosmalen Grass Court Championships|
|More to Madrid than just Ronaldo - Robertson|
|Wolff: Red Bull and Ferrari favourites in Monaco|
|Iniesta hailed by Xavi as ´the most talented player in the history of Spain´|
|If you Googled ´European nights´, Liverpool would be top result - Klopp|
|Icardi cut from Argentina World Cup squad|
|Test recall a ´fantastic surprise´ for Buttler|
|Klopp needs Premier League to be a Liverpool great – Johnston|
|Salah is ´definitely´ world´s best - Lovren|
|Rhinos captain Watkins ruled out for eight months|
|No clue - Klopp defiant over Can to Juventus claims|
|Younis tips Babar for Pakistan greatness|
|Germany squad numbers hint at World Cup good news for Neuer|