Franck Kessie's penalties gave Milan a 2-0 victory that secured their return to the Champions League after a seven-season absence as Atalanta finished with 10 men.
Milan led the way in the Scudetto race until February but fell off the pace and went into the final weekend knowing that defeat could see them slip to fifth and miss out on a place in Europe's premier club competition.
They showed little desire to attack Atalanta, who were already guaranteed to finish in the top four, but moved ahead two minutes before half-time thanks to Kessie's first spot-kick.
Marten de Roon was shown a red card – a little shove on the referee in response could land him in further bother – following the awarding of a second penalty in second-half stoppage time that Kessie slotted home to spark jubilation in the Milan camp.
Milan spent much of the first half successfully absorbing Atalanta pressure but they were awarded a chance to go ahead when Joakim Maehle felled Theo Hernandez in the box.
Former Atalanta midfielder Kessie confident stepped up and drilled the resulting penalty into the bottom-left corner in a massive moment for Milan.
Gian Piero Gasperini sent on Luis Muriel for the second half but the hosts struggled to test Gianluigi Donnarumma.
They nearly fell two behind in the 69th minute when Kessie surged forward and fed Rafael Leao, who saw his dink over Pierluigi Gollini hit the upright.
Milan continued to defend well as Atalanta looked for an equaliser that would have secured an unprecedented second-place finish for the club.
However, referee Maurizio Mariani pointed to the spot when Hakan Calhanoglu's mishit deflected off Jose Luis Palomino and struck Robin Gosens on the arm.
De Roon was dismissed for violent conduct in an ensuing melee and he responded by pushing the referee.
Kessie was eventually able to take his penalty and he converted again to ensure it was Napoli who missed out on Champions League qualification.
What does it mean? Milan save some face
The Rossoneri were in danger of becoming only the second team to finish outside the top three in Serie A after leading at the halfway stage – Juventus being the other side when they slipped from first to fifth in 1935-36.
However, Kessie's penalties clinched a valuable victory that secured their best league finish since 2011-12, lightening the blow of seeing arch-rivals Inter lift the trophy earlier on Sunday.
The Rossoneri also made history by becoming the first team to win 16 Serie A away games in a single season, breaking a record that was set by Inter in 2006-07.
Franck deserves a Kessie
With a pair of penalties, Kessie became the first Milan player to score 11 spot-kicks in a single Serie A campaign in history. Only Cristiano Ronaldo (12) and Ciro Immobile (14) have registered more across one season.
Maehle has a mare
The way Atalanta were playing it seemed like it would only be a matter of time until they got the opening goal, but Maehle's reckless challenge on Kessie changed the game. He gave away possession 12 times and failed to win any of his eight duels.
Key Opta Facts
- Milan will return to play in the Champions League for the first time since 2013-14 (when they were eliminated in the last 16 by Atletico Madrid).
- The Rossoneri have set a new all-time record for away wins in a Serie A season: 16. No side has ever done better in the top-five European leagues in a single campaign (16 also for Real Madrid in 2011-12 and Manchester City in 2017-18).
- Franck Kessie is the first Milan player to score two penalties in a single Serie A match since Kaka in April 2009 against Palermo.
- Atalanta have failed to score in only two of their past 21 Serie A matches: both against Milanese sides (the previous against Inter last March).
- Milan have kept a clean sheet in five consecutive Serie A games for the first time since March 2006.
- Stefano Pioli's side have taken the most penalties (20) in a single Serie A season since 2004-05 (when Opta started to collect this data).
What's next?
Milan will hope Champions League qualification enables them to tie Gianluigi Donnarumma and Calhanoglu down to new contracts, with Atalanta also able to look forward to another season in Europe's premier club competition.