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 — which would require treatment over a three-month period.
The former Manchester City forward has since been subjected to 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.
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.
He was making just his fifth appearance — and only his second start — for his new club in the Alaves game on Oct. 30.
Aguero burst onto the scene in Argentina as a teenager with Independiente before signing for Atletico Madrid in 2006. He scored 102 goals in five years in Spain before joining City in a deal worth around €40 million.
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 goalscorer 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.