The Rossoneri racked up two goals within 16 minutes, thanks to Urby Emanuelson's deflected strike and yet another wonder goal from Stephan El Shaarawy, but Hulk and Roman Shirokov soon dragged Zenit back into the game.
Christian Abbiati held the reinvigorated Russians at bay with a string of stunning saves - most remarkably keeping out a Hulk piledriver - before Tomas Hubocan's unfortunate own-goal sealed Milan's first win in Group C.
The precious European victory should also prove to be just the tonic ahead of the first 'Derby della Madonnina' of the Serie A season.
With one eye on the challenge presented by Inter Milan this Sunday, Allegri told acmilan.com following the Zenit triumph: "The lads were looking for a win but they had to struggle to get it.
"We kept on going despite the Russian response and the lads did very well. Abbiati did really well on a few occasions.
"I maybe need to start with three in midfield because we were struggling to get out of our own half at times.
"I think taking another look at our tactics could be important, we need to learn from some of the events that happened tonight [Thursday].
"We'll protect El Shaarawy just like the other youngsters because it's the right thing to do, he can still improve.
"Now there are three days to prepare for the derby and we hope to find the right recipe to come through such a big challenge."
Milan goalkeeper Abbiati admitted it was more than just another day at the office, adding: "It was good to get a result here, we struggled but we managed it in the end.
"My last save was crucial to the final result and I'm happy I pulled it off.
"I don't read the papers when I'm playing well or when I'm playing badly. This was a victory for the whole team, for Milan."
Aged 19 years and 342 days, El Shaarawy became the youngest ever Milan player to score in the Champions League.
He said: "I'm really happy with my goal but most of all with the victory.
"I'm determined to keep my feet on the ground, I've already showed that I want to improve day by day and show how important I can be to Milan.
"But this is not the time for backslapping and we're fully focussed on the future."