"After speaking with those closest to me, I've come to realise that my health and my family's health comes before anything else," the Northern Irish world number four said in a statement on Wednesday.
"Even though the risk of infection from the Zika virus is considered low, it is a risk nonetheless and a risk I am unwilling to take."
The 27-year-old McIlroy was due to represent Ireland at the Games and his withdrawal is the latest blow to golf, which is returning to the Olympics for the first time since 1904.
A number of big names including Fiji's Vijay Singh and Charl Schwartzel of South Africa have also withdrawn because of the virus.
Controversy over the Games has grown as more about Zika becomes known. The mosquito-borne virus can cause crippling birth defects and, in adults, has been linked to the neurological disorder Guillain-Barre.
Last week, the World Health Organisation (WHO) said that the Games did not need to be moved or postponed because there is "a very low risk" that holding the event in Brazil will cause further spread of the virus.
An expert WHO panel on Zika concluded that staging the event during the Brazilian winter means the mosquito population will be smaller and intensified mosquito-control measures in place around venues "should further reduce the risk of transmission".
But there are clearly worries in the golf world. Earlier this month, world number one Jason Day expressed doubts for the first time over whether he would compete and the virus was a hot topic of conversation among golfers at last week's US Open.
Masters champion Danny Willett, whose wife Nicole gave birth to their first child at the end of March, said he was excited about the Olympic Games but would not to go if his family's health was at risk.