The 45-year-old said he was participating in the “toughest Ironman in the world” to “break the stigma” around the illness.
Thomas, a former British and Irish Lions captain – who came out as gay in 2009, is thought to be the first UK sportsman to go public about living with HIV.
In an emotional video posted on his Twitter page, the former Wales star announced his diagnosis.
He said: "I want to share my secret with you.
"Why? Because it's mine to tell you.
"Not the evils that make my life hell, threatening to tell you before I do. And because I believe in you and trust you.
"Now you have that information, that makes me extremely vulnerable, that does not make me weak."
His decision to speak out has been backed by charities and high-profile figures, including the Duke of Cambridge.
Prince William retweeted Thomas’s video, adding: “Courageous as ever – legend on the pitch and legend off it. You have our support Gareth. W”
The Terrence Higgins Trust - the UK's leading HIV charity - tweeted Thomas "isn’t just living with HIV, he is thriving."
"We couldn’t be prouder."
While BBC presenter Huw Edwards wrote "this takes exceptional courage."
Thomas was one of hundreds of athletes who gathered on the start line for the Ironman Wales race in Tenby.
He completed the 2.4 mile swim section in Carmarthen Bay in just under an hour-and-a-half, before switching to a push bike for a 112-mile race across south Pembrokeshire.
The final leg of the challenge will see him take on a 26.2 mile marathon through Tenby, in south west Wales.
In an interview with the Sunday Mirror, he said he was driven to suicidal thoughts as a result of his diagnosis.
Thomas said he went public with his illness after being put “through hell” by blackmailers who threatened to expose his secret.
He told the newspaper: "I’ve been living with this secret for years.
"I’ve felt shame and keeping such a big secret has taken its toll.”
"I was in a dark place, feeling suicidal. I thought about driving off a cliff.
"To me, wanting to die was just a natural thought and felt like the easier way out, but you have to confront things."
The former British Lions captain, 45, who will be a TV pundit in the upcoming Rugby World Cup, said he "broke down" when he got the news of his diagnosis.
He explained: "I went for a routine sexual health test at a private clinic in Cardiff.
"I didn’t feel ill and thought everything was going to be fine.
“When (the doctor) said those words… I immediately thought I was going to die.
"I felt like an express train was hitting me at 300mph.
"Then I was thinking ‘how long have I got left?'"
The sportsman now takes one tablet containing four medications each day, and doctors have said his condition is under control to the point that it is considered "undetectable" and cannot be passed on.
Mr Thomas said that his partner – Stephen – who he met after his diagnosis and married three years ago, does not have HIV.
He said he hopes that his openness will help end the stigma around condition.
He said: "I’m speaking out because I want to help others and make a difference.
"I hope me speaking out about my diagnosis will help a lot of people."
The former Cardiff Blues player won 103 caps and scored 41 tries for Wales between 1995 and 2007, and he is 13th on the all-time international test try-scoring list.
Last November, he was attacked in Cardiff city centre in a homophobic hate crime, but asked South Wales Police to deal with the 16-year-old assailant by way of restorative justice.