Napoli must not lose to Torino on Monday (AEST), or it will mean Juventus being crowned Serie A champion again.
Massimiliano Allegri's men looked in trouble after falling 1-0 down to their visitors in the first half, but they rallied with a vengeance in the second period, half-time substitute Costa playing a starring role with two assists to ensure they head into the Coppa Italia final against AC Milan on Thursday (AEST) in high spirits.
Juve's start gave no indication it would need another comeback like it did to beat Inter Milan last time out, as it caused Bologna's backline plenty of problems.
But a Gianluigi Buffon error coupled with a clumsy Daniele Rugani tackle allowed Simone Verdi to put Bologna ahead from the penalty spot in the 30th minute, the centre-back saved from a red card by VAR (video assistant referee).
With Juve offering little out wide, Allegri sent Costa on from the bench at the interval and his impact was as desired, but it was a Sebastien De Maio own goal that restored parity.
Costa set up two goals in six minutes just after the hour mark, finding Sami Khedira and then Paulo Dybala to seal all three points for Juve, leaving it on the brink of a seventh successive title.
There was no sign of early Bianconeri nerves as they made a strong start and nearly went ahead in the seventh minute, Gonzalo Higuain drawing a good save from Antonio Mirante after Claudio Marchisio carved the visitors defence open.
Bologna was guilty of a defensive mishap a few minutes later, as Dybala robbed De Maio just outside the area before seeing his effort deflected harmlessly over.
But Juve shot itself in the foot after half an hour, Buffon selling Rugani short with a pass that forced the centre-back to haul the sharp Lorenzo Crisetig to the ground in the area.
Although the VAR review which concluded Rugani should not be sent off took a while, Verdi kept his cool to dispatch the spot-kick in remarkably confident fashion.
Juve failed to threaten again before the break and Allegri responded at half-time by introducing Costa on the left wing for Blaise Matuidi, with the Brazilian making a significant difference.
But the equaliser came via the opposite flank, Juan Cuadrado's curling cross calamitously flicked into the back of the net by Bologna defender De Maio.
Juve was lucky to remain on level terms just before the hour mark, however, as a cross found its way through to Emil Krafth and Buffon tipped his effort onto the post.
The host soon capitalised on that let-off, Costa's deep left-wing delivery finding Khedira at the back post for an easy finish.
The Brazil international was at it again in the 69th minute, tearing up the left and playing a low cross into the area for Dybala to guide home.
It was plain sailing from there for the defending champion, as it heaps the pressure back on Napoli ahead of its meeting with Torino.