The 41-year-old's Milan contract expires at the end of June and will not be renewed following a season plagued by injuries, prompting him to end a remarkable and successful career.
But Ibrahimovic later revealed in a news conference that no one knew the big announcement he was about to drop.
"Even my family didn't know, because I wanted that when I announced it everyone heard it at the same time," he said.
Ibrahimovic scored 93 goals in 163 appearances over two spells at Milan. He returned in January 2020 and helped Milan win the Serie A title last year -- his second league trophy with the Rossoneri.
The prolific striker, who had 561 goals for club and country over the course of his career, had tears in his eyes on the sidelines as the Milan fans unfurled a giant banner at one end saying "Godbye" and chanted his name. Ibrahimovic cupped his hands in the shape of a heart and blew kisses to the fans.
There was also a special ceremony dedicated to him after the match, with the Milan players and staff giving him a guard of honor as he walked out onto the field.
"I say goodbye to football, but not to you," he said after being feted by the San Siro crowd following Milan's 3-1 win over Hellas Verona in their season finale.
The striker started his professional career at Malmo FF in 1999 and left for Ajax Amsterdam in 2001 before embarking on a career that has included leading European teams including Manchester United, Paris Saint-Germain, Inter Milan and Milan.
Ibrahimovic had struggled with injuries and only made four appearances this season for Milan, after undergoing a knee operation last year.
"I have so many memories and emotions inside this stadium," he said. "The first time I arrived you gave me happiness, the second time you gave me love.
"I want to thank my family. I want to thank my second family: the players. I want to thank the coach and his staff for the responsibility, I want to thank the directors for the opportunity. Last but not least, from my heart, I want to thank you fans."
Ibrahimovic, Sweden's all-time top scorer with 62 goals in 121 matches, quit the national team after Euro 2016 but returned in 2021 for their unsuccessful World Cup qualifying campaign. He scored the most goals in his career with PSG, netting 156 times in 180 matches, while finding the back of the net 53 times in his 55 games played for the LA Galaxy in MLS.
Ibrahimovic ended his speech with a smile and in his typical flamboyant style.
He said: "It's too difficult, there are so many emotions going through me now. But I will say, 'I'll see you around, if you're lucky.'
Reuters and The Associated Press contributed to this report.