On Friday, the 30-year-old tweeted a press release, saying he had been following a doctor-prescribed medical treatment that he didn't realise contained a banned substance-testosterone.
"I would never knowingly violate anti-doping rules," Dwyer said. He added that he was retiring from swimming.
"Today I'm announcing my retirement from professional swimming. It has been an incredible ride and I have accomplished more than my wildest dreams. It was an honor to represent my country alongside my teammates."
In his statement, Dwyer said he received assurances from his doctor that the USOPC had approved of the treatment.
"Absent of these assurances, I never would have agreed to this medically necessary treatment," Dwyer wrote.
Dwyer won gold in the 4x200-meter freestyle relay at the 2012 and 2016 Olympics, and bronze in the 200-meter freestyle in 2016.