On an eventful day of each team’s second Test match, spinners bagged nine of the 12 wickets.
Murtagh, 37, made an unbeaten 54 off 75 balls to keep Ireland going until they were bowled out just before tea, much to the frustration of Afghanistan.
Ireland’s left-arm spinner James Cameron-Dow, on debut, had Ihsanullah Jannat leg before wicket and took a scorching two-handed catch off his own bowling to dismiss Mohammad Shahzad on 40 in the last session.
Rahmat Shah was unbeaten on 22 and Hashmatullah Shahidi 13 not out at stumps. Afghanistan still trailed by 82 runs with eight wickets in hand.
Ireland had earlier collapsed to 85-9 soon after lunch against the spin trio of Mohammad Nabi, Rashid Khan, and debutant Waqar Salamkheil, who shared seven wickets before Murtagh led the counterattack.
With George Dockrell proving a perfect foil to Murtagh, they added 87 runs and saved Ireland from total humiliation. Dockrell made 39, and Murtagh hit four boundaries and two sixes.
Fast bowler Yamin Ahmadzai finally ended Ireland’s resistance when he had Dockrell caught behind. He took 3-41.
Earlier, Ireland had a woeful first session when they were reduced to 69-7 by lunch.
Opening batsman Paul Stirling smashed six fours in a breezy knock of 26, and captain William Porterfield appeared to have made the right decision to bat first.
Stirling hit fast bowler Ahmadzai for three offside boundaries in one over, then Ireland collapsed and lost seven wickets in 25 runs.
Ahmadzai bagged Stirling, who was caught behind, and knocked back Andy Balbirnie’s stumps off an in-swinger in his next over.
In between, Nabi (3-36) had Porterfield trapped lbw in his second over.
Rashid (2-20) ran Ireland into deep trouble when he dismissed two of the five Ireland debutants in his first over. James McCollom was clean bowled off a sharp googly first up, and one ball later Stuart Poynter was lbw off a full toss as Ireland slipped to 55-5.
Nabi added the wickets of veteran Kevin O’Brien for 12 and Stuart Thompson for 3. Thompson took 27 balls to get off the mark before giving a sharp close catch.
The unorthodox left-arm spinner Salamkheil (2-35) removed Andy McBrine and Cameron-Dow after lunch but Murtagh’s brilliant half-century denied Afghanistan until tea.
There were three Test newcomers for Afghanistan: Batsmen Janat and Ikram Ali Khil, and fast bowler Waqar Salamkheil.