Aguero has not played since the end of October, when he was taken off during the first half of Barca's draw with Alaves after experiencing chest pain.
Barcelona later announced that the discomfort had been caused by an arrhythmia -- a broad term to describe any heart rhythm that is not completely normal -- that would require treatment over a three-month period.
The former Manchester City forward has since had regular cardiac exams to monitor his health, with the results advising him it would be a risk to carry on with his professional career.
He announced his retirement at a news conference on Wednesday, joined by Barca president Joan Laporta.
An emotional Aguero said: "This conference is to announce I have decided to stop playing professional football. It is a very difficult moment. The decision I have taken for my health; the problem I had a month and a half ago.
"I have been in good hands with the medical staff. I made the decision 10 days ago after doing everything possible to have some hope of playing on. I am very proud for my career. I always dreamed of a professional career since the first time I touched a ball at 5.
"I want to thank Atletico Madrid, who took a chance on me when I was 18, and Manchester City -- everyone knows who I feel about City and how well they treated me there."
Former Barcelona star Lionel Messi had kind words for his former teammate via an Instagram tribute.
"Practically all of our career together, Kun... We have lived very beautiful moments and others that were not so much so, but all of them brought us together even more and made us closer as friends. And we are going to continue to live moments together off the pitch," Messi wrote.
"With so much happiness to lift the Copa America such a short time ago and with all of your accomplishments in England, the truth is that it hurts a lot to see how you must leave what you love the most due to what has happened.
"I am sure you will continue to be happy because you are the type of person who radiates happiness and those of us who love you are going to be with you. Now you will start a new stage in your life and I am convinced that you are going to live it with a big smile and with all the same hopefulness that you put into everything.
"I wish you the best in this new stage!!! I love you very much my friend and I am going to miss our times together on the pitch and with the Argentina national team!!!"
Barca legend and City manager Pep Guardiola was in attendance at Camp Nou alongside director of football Txiki Begiristain. The entire Barca first-team squad and representatives from Aguero's former clubs were also present.
"Sergio, I think, as we just saw, we are left with deep joy and excitement with what you could have been here at Barcelona, but anything you need with your condition we are here at your disposal," Laporta said.
"You will be remembered not just as a player, but as a friend. A new journey awaits, and I am sure it will be just as successful. You deserve it."
City also paid tribute to Aguero on social media and posted: "King Kun. Everyone at Manchester City would like to take this opportunity to thank @aguerosergiokun for his incredible contribution to our success over the last decade and wish him well in his retirement."
King Kun.— Manchester City (@ManCity) December 15, 2021
Everyone at Manchester City would like to take this opportunity to thank @aguerosergiokun for his incredible contribution to our success over the last decade and wish him well in his retirement 💙 pic.twitter.com/AgMWXZtPZ8
Said Aguero: "I feel OK right now. Obviously the first two weeks were really difficult. When they did the first physical test on me, the medical staff told me there was a very big possibility I would not be able to continue playing.
"I am still processing everything. Then they called me to tell me it was definitive. Right now, I am OK, but I know it was difficult."
Aguero joined Barca on a free transfer in the summer from City. A calf injury delayed his debut until October, with his first goal coming in the Clasico defeat to Real Madrid.
Madrid also paid tribute to Aguero online and posted: "It was an honour to compete against a player like you, one of the best players in the world. Good luck to you and your family."
Aguero was making just his fifth appearance -- and only his second start -- for his new club in the Alaves game on Oct. 30 when he experienced breathing problems.
Aguero had burst onto the scene in Argentina as a teenager with Independiente before signing with Atletico Madrid in 2006. He scored 102 goals in five years in Spain before joining City in a deal worth around €40 million.
Atletico sent a message to the striker on social media and wrote: "Thanks for the memories, Sergio. We wish you all the best. It was an honour to enjoy your football in red and white. Good luck."
In Manchester, Aguero scored the dramatic last-minute winner against Queens Park Rangers on the final day of the 2011-12 season to help City win their first Premier League title.
In total, he won 15 trophies in England, including five league titles, and is City's record goal scorer with 260 goals in 390 appearances.
Aguero has also won 101 caps for Argentina, scoring 41 goals, and was part of the squad that won the Copa America last summer and was a runner-up at the World Cup in 2014.
When asked to recall his favourite goals, Aguero replied: "The goal for Independiente against Racing when I was 17 was one of the best that I ever scored. Winning the Europa League with Atletico was a really happy moment, and then obviously with City the goal I scored to win the first Premier League, for me and City, was a beautiful moment.
"There are a lot, and the last was the Copa America. I only played two or three matches, but it was something that we had been looking for for years and years.
"And of course, I will take my last goal against Madrid. It is not bad for a last goal, is it?"