AVA- Paul Stirling (71) and captain William Porterfield (53) combined for a 99-run partnership as the hosts were bowled out for 210 with seven balls left.
Afghanistan reached 94-4 before the final six wickets fell for 44 runs.
Mark Adair took 4-19 while Boyd Rankin (3-40) and Tim Murtagh (2-12) also impressed in the Irish attack.
Ireland lost all three of their completed Tri-Nations games against West Indies and Bangladesh and another defeat looked likely after posting a below-par 210.
Stirling and Porterfield, who was moved to number four after poor form as opener, put on an Irish record stand of 174 for the third wicket against Bangladesh last Wednesday.
The pair laid the foundation for the Irish innings again with a stand just shy of a century after Afghanistan won the toss and elected to field.
Kevin O'Brien added 32 but it was advantage Afghanistan with Aftab Alam (3-28) and Dawlat Zadran each taking three wickets.
Murtagh triggered Afghanistan's struggles with the bat by taking the first two wickets and leaving the tourists on 19-2.
The tourists' hopes faded when a fifth-wicket partnership between Asghar Afghan (29) and Mohammad Nabi (27) was ended with a Gary Wilson catch.
It was a much-needed win for the Irish and the teams will meet again at the same venue on Tuesday.