Serie A: Livorno 2 Milan 2
The striker struck his second of the game with six minutes to go to spare Milan's blushes after Livorno had come close to a famous victory.
Paulinho's sixth goal of the season looked to have won it for Livorno, but Balotelli's superb free-kick saw the points shared on Saturday.
It was Balotelli who had given Milan the lead in the seventh minute with a close-range finish, but Allegri's men were unable to hold onto their lead as Luca Siligardi levelled for the hosts.
Milan remain eighth after the draw, while the hosts stay on the edge of the bottom three.
Livorno coach Davide Nicola, himself under fire following a slump in fortunes, made four changes to his side after three consecutive defeats with Andrea Coda, Andrea Luci, Joseph Duncan and Ibrahima Mbaye all returning to the starting line-up.
Philippe Mexes and Cristian Zapata both came into the heart of defence for Milan, while 21-year-old Gabriel continued in goal.
Buoyed by back-to-back wins over Celtic and Catania, Milan made the perfect start to open the scoring after seven minutes through Balotelli after neat work from strike partner Kaka.
The Brazilian fired a low cross in from the left and the striker bundled home his fifth league goal of the season after Francesco Bardi had failed to collect.
Livorno withstood more Milan pressure and levelled through Siligardi with their first shot on target.
The striker got the ball onto his left foot, drifted past the challenge of Nigel de Jong and curled his shot beyond the outstretched arm of Gabriel.
A scruffy start to the second half saw Livorno enjoy the better opportunities and Duncan went closest to giving them the lead in the 53rd minute with a fierce left-footed drive that Gabriel held.
Paulinho made Balotelli pay for a wasted opportunity as he put Livorno ahead in the 58th minute. The Brazilian striker latched onto a through-ball from Siligardi and fired low past Gabriel at his near post.
With time running out, Milan needed something special to get them back in the game - and Balotelli was the man to provide it.
The Italy international – ploughing a low furrow - was fouled 30 yards from goal and lifted himself up to fire an unstoppable free-kick past Bardi.