The AC Milan striker made the announcement on the San Siro pitch following his club’s final game of the Serie A season on Sunday.
“I have many memories and many emotions in here,” the Sweden international said.
“The first time I arrived here you gave me happiness. The second time, love. I will be a Milan fan for life.
“The time has come to say goodbye to football, but not to you. See you around, if you’re lucky. Forza Milan and goodbye.”
A clearly emotional Ibrahimovic was serenaded by the Milan fans and then given a guard of honour by his teammates as he left the pitch.
The former Manchester United striker has spent most of the season on the sidelines due to injury.
He played just four times for AC Milan and scored once in a 3-1 defeat at Udinese in March, and his departure from the club had already been announced.
In July last year he renewed his contract for another year, in spite of facing the prospect of a lengthy rehabilitation from knee surgery.
Shortly after helping AC Milan win the Serie A title he had undergone a planned procedure on his left knee.
It was to repair damage and instability caused by a previous anterior cruciate ligament injury.
As expected that meant a lengthy lay-off and Ibrahimovic did not make his first appearance of this season until the end of February.
Ibrahimovic began his career at Malmo and joined Ajax in 2001 after rejecting the overtures of Arsenal manager Arsene Wenger.
“Arsene Wenger asked me to have a trial with Arsenal when I was 17. I turned it down. Zlatan doesn’t do auditions,” was how Ibrahimovic put it in his own inimitable style.
The prolific striker also had spells with Juventus and Inter Milan before an unhappy spell at FC Barcelona, where he complained about how he was used by manager Pep Guardiola.
“When you buy me, you are buying a Ferrari,” Ibrahimovic said.
“If you drive a Ferrari you put premium fuel in the tank, you drive on to the motorway and you floor the accelerator.
“Guardiola filled up with diesel and went for a spin in the countryside. If that’s what he wanted, he should have bought himself a Fiat from the start.”
Ibrahimovic joined AC Milan for the first time, initially on loan, in 2010 before moving to Paris St-Germain (PSG), where he scored 113 times in 122 league appearances.
He also enjoyed spells with Manchester United, with whom he won the Europa League and League Cup, and LA Galaxy before returning to the San Siro.
Sweden’s all-time top scorer with 62 goals in 122 matches, Ibrahimovic quit the national team after Euro 2016 but returned in 2021 for their unsuccessful World Cup qualifying campaign.(dpa/NAN)