The visitors took a shock lead in controversial fashion when Simone Verdi converted a penalty following a lengthy stoppage for VAR, and they held on to that advantage until half time.
However, a second-half comeback from the champions saw them turn the game around, with an own goal from Sebastian De Maio levelling things up before Sami Khedira and Paulo Dybala made sure of the victory.
The result lifts Juventus seven points clear at the top of the Serie A table, meaning that defeat for second-placed Napoli against Juve's city rivals Torino on Sunday would hand the Old Lady an unprecedented seventh title in a row.
Bologna remain winless on the road this calendar year, but they more than held their own in the first half and came close after 19 minutes when Lorenzo Crisetig got on the end of a free kick, only to steer his header straight at Gianluigi Buffon.
The visitors may have been beginning to dream of a win which would have guaranteed their Serie A survival when they took the lead, although almost four minutes separated the awarding of the penalty and the spot kick actually being converted.
Daniele Rugani was penalised for a trip inside the penalty area following a suicidal pass from Buffon and, after a lengthy VAR consultation which saw the original decision upheld, Verdi managed to keep a cool head by placing his finish straight down the middle from 12 yards.
Gonzalo Higuain looked the most likely throughout the first half for Juventus, but he was denied on a couple of occasions by Antonio Mirante as the hosts went into the break facing the prospect of back-to-back home defeats for the first time since March 2011.
It was Juan Cuadrado on the opposite flank who provided the cross which led to the equaliser, though, with De Maio getting his attempted clearance all wrong to slice the ball into his own net.
Costa produced a man-of-the-match display during his 45 minutes on the field, and he almost got his own name on the scoresheet moments after the equaliser when he cut inside before forcing a save from Mirante, whose parry had just enough on it to deny Cuadrado a tap-in from the rebound.
Mirante was back in action again just a minute later when he was alert enough to come off his line and thwart Higuain, who took too long over his finish after being found in space on the edge of the box.
There was a scare for the hosts on the hour mark, though, as Emil Krafth collected a cross which had somehow made it all the way to the back post, but Buffon pulled off a crucial one-on-one save to tip his effort against the post.
Juve's second had an air of inevitability about it, though, and it was no surprise to see Costa play a major role as his cross to the back post took Mirante and Cheick Keita out of the game, allowing Khedira to cushion his first-time volley into the empty net.
A third arrived just five minutes later as Costa produced another assist, racing to the byline before cutting the ball back for Dybala, who swept his finish past the keeper to all but wrap up the points for the Old Lady.
Allegri's side safely saw out the match with minimum fuss during the closing stages, and their celebrations at the final whistle were those of a team who know they are on the brink of another title, with the possibility of their seventh successive crown being confirmed as early as tomorrow.
Bologna, meanwhile, could also see their Serie A survival confirmed tomorrow as they remain 12th in the table and eight points from danger.
JUVENTUS (4-3-3): Buffon; Cuadrado (Lichtsteiner 72'), Barzagli, Rugani, Asamoah; Khedira, Marchisio, Matuidi (Costa 46'); Dybala, Higuain, Sandro (Bernardeschi 84')
BOLOGNA (5-3-2): Mirante; Krafth (Torosidis 60'), M'baye, Romagnoli, De Maio, Keita; Poli, Crisetig, Nagy; Verdi (Destro 73'), Avenatti (Palacio 66')