Allegri says it was crucial for Milan to stay within a point of Juventus.
"At this moment the table has stretched out a ban, so it was important for us to win tonight," he said.
"We're still close to Juve and have broken away from the chasing pack, as both Udinese and Inter lost this weekend.
"We played a good game, even if it was a struggle up until Zlatan Ibrahimovic's goal. After that, it was much simpler."