The 38-year-old Swede had come on as a substitute in AC Milan's goalless draw against Sampdoria last weekend, days after his return to Italy.
Ibrahimovic met a cross Theo Hernandez after 64 minutes in Sardinia with a low-first time shot into the far corner. It was his first Milan goal since leaving the club for Paris Saint-Germain eight years ago.
Portuguese forward Leao, 20, had struck the opener just after the break as Milan got their first win in just over a month.
AC Milan move up to eighth in the Serie A table, 10 points off the Champions League berths.
It was a disappointing performance for Cagliari as the Sardinians unveiled the new jersey to mark the 100th anniversary of the club this year.
Cagliari remain sixth after their fourth consecutive defeat.
Ibrahimovic started up front alongside Leao, who had described the towering Swede "as a big brother".