Milan signed off 2016 with an encouraging penalty shoot-out triumph over Juventus in the Supercoppa Italiana but struggled to force a way past the stubborn visitors at San Siro until the intervention of Bacca, who waited until the 88th minute to strike for the first time since October 2 with a vital effort.
Substitute Gianluca Lapadula showed brilliant determination and invention to hook a loose ball into the path of the Colombian striker despite being on the floor in the opposition’s penalty area.
Bacca finished with aplomb to secure all three points and then caused Bruno Alves to receive his marching orders, the veteran defender bringing him down to deny a clear sight of goal in stoppage time.
Cagliari had appeared on course to improve on their terrible defensive record from the first half of the campaign, the Sardinian side having conceded 42 goals from their first 18 matches of the league season – the worst record in the competition.
That fragility was nowhere to be seen for much of the game, as the likes of Bacca, M’Baye Niang and Suso all laboured without noticeable reward until the former Sevilla man finally came to life.
The result sees Milan climb to fifth, inside the Europa League qualification berths, and just two points off the Champions League places.
Alessio Romagnoli went close to opening the scoring for Milan with a near-post header from a corner just two minutes in and Bacca then flashed a shot wide of the upright seconds later, but the hosts struggled to mount a consistent threat after that early flurry.
Alves made his mark on the contest when a heavy challenge forced Ignazio Abate to be withdrawn after 27 minutes, Luca Antonelli his replacement.
Niang fired an effort just over the bar and Giacomo Bonaventura sent a free-kick close shortly before the half-hour mark.
Those chances came either side of a good stop from Gianluigi Donnarumma, who had to be alert to block a shot from Nicolo Barella with what was Cagliari’s only opportunity of note in the opening 45 minutes.
The away side offered several more warning shots after the break, Daniele Dessena hooking an effort inches over the bar from the top of the box five minutes into the second half.
And Cagliari had the ball in the back of the net in the 68th minute, but a late flag from the assistant referee denied the visitors the opener.
It was a long time coming, but replays showed Mauricio Isla was one of two players in an offside position when he tucked home from Diego Farias’ deflected shot.
That was as close as Cagliari came to springing a surprise and they were ultimately left empty handed as those familiar defensive frailties were exposed by Bacca with two minutes remaining.
Alves’ late dismissal means he will be unavailable for next Sunday’s league match against Genoa, while Milan are in Coppa Italia action against Torino on Thursday.