Rafael Leao put AC Milan ahead in the ninth minute before Sampdoria found an equaliser.
Browsing: Brahim Diaz
Fikayo Tomori sent the home side ahead in the final stages of the first half before Brahim Diaz registered early in the second half.
The victory moved his side within a point of the Serie A leaders.
The hosts were roared into action by a brilliant crowd in an electric San Siro as they enjoyed their first Champions League home game in seven years.
Milan will not have an option to buy the player permanently, so Diaz will return to Madrid in 2023.
But the Italians had to withstand a late barrage from the Scottish champions to secure the three points.