The veteran former LA Galaxy striker has signed a six-month contract with the Rossoneri, whom he previously played for between 2010 and 2012.
The 38-year-old, a substitute in the goalless draw against Sampdoria, notched on his return to the starting XI to score in four different decades – his first goal coming for Malmo in 1999.
Rafael Leao had put Milan in front early in the second half with a deflected effort following a free-kick.
Ibrahimovic made it 2-0 in the 64th minute with a low finish into the bottom corner from Theo Hernandez's cutback.
The Swede thought he had headed in a late second but was ruled offside.
Martinez saw his angled lob cleared off the line then just before half-time Atalanta defender Rafael Toloi had his header from a free-kick saved by Handanovic.
The Nerazzurri, though, were pegged back with 15 minutes left when Robin Gosens hooked the ball in at the far post.
Juventus can move two points clear at the top of the table if they win at Roma on Sunday.
Napoli had been unfortunate not to break the deadlock in the 68th minute when Piotr Zielinski's curling effort came back off the inside of the post.
Then with just seven minutes left, Napoli goalkeeper David Ospina was caught out when trying to dribble around Immobile.
The forward was able to shrug the goalkeeper off the ball and spin to clip the ball in from a tight angle past defender Giovanni Di Lorenzo.
Yoann Court had given the visitors the lead from a swift break after seven minutes.
However, defender Bafode Diakite headed in from two corners in the space of four first-half minutes to turn things around.
Toulouse were looking to end a terrible run of 10 straight defeats in all competitions – which included a shock Coupe de France loss to minnows St Pryve St Hilaire.
However, Brest mounted a second-half recovery as Gaetan Charbonnier scored twice in the space of five minutes, the first an acrobatic volley, before substitute Hianga'a M'Bock made it 4-2 with a long-range drive in off the crossbar.
Irvin Cardona crashed home a late fifth to complete another miserable evening for Toulouse.
Elsewhere on Saturday, Montpellier are fifth after coming from behind to win 2-1 at struggling Amiens.
The home side, who sit 18th, went ahead when Bakaye Dibassy knocked in a rebound in the 14th minute.
Gaetan Laborde equalised early in the second half, nodding in a deep free-kick, with a fine volley from Andy Delort sealing victory late on.
Lyon won 2-1 at Bordeaux and are sixth.
Jimmy Briand put the hosts ahead following a defensive mix-up on 15 minutes.
However, Maxwel Cornet and Moussa Dembele scored early in the second half to complete the comeback.
Metz secured their first win since mid-October as John Boye's second-half goal gave them a 1-0 victory over Strasbourg.
Angers and Nice drew 1-1.
Sada Thioub (37) put the home side ahead with a low drive, before Nice equalised through a penalty from Wylan Cyprien just before half-time.
Nimes beat Reims 2-0, as the visitors finished with 10 men.
A scrambled goal from Renaud Ripart gave Nimes the lead after 15 minutes.
Reims had midfielder Alaixys Romao sent off for a second caution after 57 minutes – and Yassine Benrahou clipped in a 25-yard free-kick to seal victory during stoppage time.