Warburton, who was capped 74 times by his country and played five tests for the British and Irish Lions, led Wales in a record 49 matches.
The flanker recently returned to pre-season training with his club Cardiff Blues.
"Unfortunately, after a long period of rest and rehabilitation the decision to retire from rugby has been made with my health and wellbeing as a priority as my body is unable to give me back what I had hoped for on my return to training," Warburton told the WRU website.
Warburton led Wales to the 2012 Six Nations title and at two World Cups. His last match was the Lions' test draw against the All Blacks in June, 2017.
"I cannot thank the Welsh Rugby Union and Cardiff Blues enough, who have gone beyond the call of duty, in providing the support I received to help me get back on the field, for which I will be forever grateful," Warburton added.
Wales coach Warren Gatland, who gave Warburton the Wales and British and Irish Lions captaincy, paid tribute to his contribution to both teams.
"His leadership, attitude and demeanour along with his performances have placed Sam up there as one of the best and most respected players in the world," Gatland said.
Warburton helped the Lions beat Australia in 2013, their first series win in 16 years.
He became only the second man to skipper the Lions on two tours and led them to a series draw with world champions New Zealand last year.
"He finishes with a record that he should be extremely proud of and should look back on his career with huge pride... I hope he can take the time to reflect on a magnificent career," Gatland added.
Warburton's final match was the Lions' 15-15 draw with the All Blacks in the third test in June, 2017.