Sun tested positive for the banned stimulant trimetazidine on May 17 during China's national swimming championships in Hangzhou.
The suspension began immediately and ended on Aug. 17, prior to Sun's appearance in September at the Asian Games at Incheon, South Korea, where he won three gold medals.
Amid criticism on social media, the anti-doping agency defended its delay in announcing the 22-year-old Sun's test and sanction, saying it was for no other reason than a backlog of cases.
The agency's director, Zhao Jian, told The Associated Press the ban was announced as part of a periodic release of testing results and disciplinary measures. He said Sun's support team and team doctor were also given penalties, which he didn't specify.
Sun's sanction was also posted Monday on the website of the international swimming federation, FINA. It said the Chinese swimming association also imposed a 1-year ban on Sun's doctor, Ba Zhen.
Sun won the 400 and 1,500 metre freestyle events at the 2012 London Olympics, and also has five world championship golds. He won gold in the 400 and 1,500 and the 4x100 relay at the Asian Games.
Zhou said Sun's status as a world-famous athlete required authorities to handle his case with greater caution to ensure no mistakes were made.
"This is huge bad news but we will not cover it up," Zhao said, in comments later carried by the official Xinhua News Agency. "We usually report the violations quarterly or bi-quarterly and we have to wait until the handling of a particular case has been finished."
The need to handle almost 10,000 tests over a six-month period also slowed the process, Zhao said.
"That's why we did not release the reports for the second and third quarters until now," he said.
Zhao said Sun waived his right to have his backup "B'' sample tested, but defended himself at a July hearing by saying the positive test was caused by an ingredient in medication he was taking for a heart condition and he wasn't aware it was banned. Under World Anti-Doping Agency rules, an athlete can be permitted a therapeutic exemption if a substance is needed for medical reasons and is declared in advance to authorities.
In a statement, Sun said he accepted the anti-doping agency's decision and pledged to engage in "deep reflection."
"Whatever the cause, as an athlete, I must take responsibility for whatever enters my body," Sun said in the statement posted to his verified account on China's China's Weibo microblogging service.
Sun noted it was the first time he had been penalized despite taking "countless" doping tests over his swimming career and said the May result left him "shocked."
"From now on, I will be even more strict in my demands on myself," Sun said.
Trimetazidine was added to the World Anti-Doping Agency's list of banned substances in January.
The Chinese swimming program was overshadowed in the 1990s by a doping scandal, when 32 athletes were caught for doping-related offences, two of them twice, and another three were disqualified from a domestic competition for having excessive red blood cell counts.
Sun has been controversial at times out of the pool.
The first Chinese man to win an individual Olympic swimming gold, Sun was suspended from training and competition last December after being detained for seven days for driving without a license. He'd previously been censured after feuding with his coach and for missing practice in order to make commercial appearances and spend time with his girlfriend.
Ahead of the Asian Games in South Korea, Sun filmed a series of television advertisements gently mocking his chief rival Park Tae-hwan. In one of them, Sun, floating on an air mattress, thanks Park for not quitting swimming to become a singer or TV star. "Don't let me win too easily," he adds.
Associated Press researcher Yu Bing contributed to this report.Suggest a correction