Faheem Ashraf marked his Test debut with 61 not out and teenager Shadab Khan, in only his second match at this level, also hit a maiden Test fifty to be unbeaten on 52.
Azhar Ali faced the first ball of the match from Tim Murtagh and kept out a yorker before calling his opening partner through for a single.
The 22-year-old was left flat on the ground and needed several minutes' treatment on the field, but he recovered to face the second ball of the match, with Imam playing and missing.
But the 22-year-old left-hander, who hit a hundred on his one-day worldwide debut against Sri Lanka last year, has made fifties against both Kent and Northamptonshire in Pakistan's two warm-up matches ahead of this one-off Test.
Pakistan team is in good form as it won the tour match against Northamptonshire with 9 wickets.
Tim Murtagh celebrates as Ireland take their second wicket in Malahide.More news: Cannes 2018: Deepika Padukone stylish looks on Day 1
That left Pakistan 13 for one off the last ball of the eighth over.
To complicate matters for the visitors, Murtagh got the ball to move in to left-hander Imam and had him trapped leg before to make it two wickets in two balls, and reduce Pakistan to 13 for 2. The duo added 58 runs for the third wicket to allay fears of an absolute collapse, but Sohail's fall only reignited the possibility. Shafiq square-cut Kane for four, with left-hander Haris Sohail glancing Stuart Thompson for a legside boundary.
After a brief delay, Imam was able to carry on, with no wicket lost.
Shafiq began to steady the Pakistan ship and reached his 50 from 107 balls after the restart.
Bowling from the Dublin Road end, Murtagh was getting some early movement off a pitch that was less green than expected, and a credit to Malahide head groundsman Philip Frost and his team. When Stirling did come on, a well-set Faheem launched the part-time spinner over long-on for six.