Milan went ahead after four minutes when Ante Rebic crossed from the left and Ibrahimovic, left unmarked, headed past Sampdoria goalkeeper Wladimiro Falcone who was making his Serie A debut at the age of 25.
However, Falcone made a good save to deny Ibrahimovic a second goal before halftime when the Swede's shot took a deflection.
Donnarumma did well to stop a Fabio Quagliarella free kick after the break before Hakan Calhanoglu added a second in the 54th minute. The referee initially disallowed it for a foul but the goal was awarded following a VAR review.
Calhanoglu also set up the third with a pass to Ibrahimovic who scored from a narrow angle four minutes later. It was the 38-year-old Swede's ninth league goal since he returned for a second stint with Milan in January.
Donnarumma saved Gonzalo Maroni's penalty and, although Kristoffer Askildsen pulled one back for Sampdoria, Rafael Leao then added a fourth for Milan.
Milan stayed sixth with 63 points which will earn them a place in the Europa League second qualifying round next season.
Jose Mourinho plots cheeky bargain deal for Inter 'outcast' - Euro Papers