Rafael Leao notched the opener from Ibrahimovic’s ball – and Bologna had Adama Soumaoro sent off – before Davide Calabria drove home Milan’s second.
Ibrahimovic headed a corner into his own net, then Musa Barrow levelled.
Roberto Soriano was sent off for a dangerous foul and Bologna almost held out before Ismael Bennacer and Ibrahimovic scored from 20 yards.
Milan, who have won their past five league games, move one point above Napoli, who travel to Jose Mourinho’s Roma on Sunday.
Ibrahimovic – on his first start of the season – is the fourth player to score a Serie A goal after his 40th birthday, along with Milan legend Alessandro Costacurta, 41, and 40-year-olds Silvio Piola and Pietro Vierchowod.
He was the first 40-year-old to set up a Serie A goal since Francesco Totti in February 2017.
Ibrahimovic’s own goal was only the second he has scored in a league game in his career – after another one for Milan in a 3-1 home win over Chievo in 2010.