Christian Pulisic, served by Rafael Leao, gave the advantage in the 60th minute to Milan who dominated the match, but cruelly lacked realism in the last gesture.
It was not until the 88th minute that Noah Okafor, on an overflow from Leao, put his team to safety.
Thanks to this success, the sixth in seven matches, AC Milan is the new leader of Serie A with 18 points, three more than Inter who visits Salernitana in the evening.
This meeting marked the return to goal of Mike Maignan, absent since his exit due to a thigh strain against Newcastle during the first day of the Champions League.
The goalkeeper of the France team had a relatively quiet evening.
Lazio remains stuck in the second part of the standings (14th), with only seven points.