McCain, who lost to Obama in the 2008 presidential election, made the comment on Thursday while Obama was in Orlando visiting with the families of those killed in Sunday's attack and some of the survivors.
"Barack Obama is directly responsible for it, because when he pulled everybody out of Iraq, al-Qaida went to Syria, became ISIS, and ISIS is what it is today thanks to Barack Obama's failures, utter failures, by pulling everybody out of Iraq," a visibly angry McCain told reporters in the Capitol as the Senate debated a spending bill.
"So the responsibility for it lies with President Barack Obama and his failed policies," McCain said.
The gunman, Omar Mateen, killed 49 people and injured more than 50 in the attack at a gay nightclub. The 29-year-old Muslim born in New York made calls during the attack saying he was a supporter of the Islamic State. But he also spoke about an affiliate of al-Qaida and Hezbollah, both of which are IS enemies.
In the aftermath of the shooting, presumptive Republican presidential nominee Donald Trump has accused Obama of putting US enemies ahead of Americans.
Trump also has suggested that Obama himself might sympathize with radical elements.
Democrats criticised Trump and some Republicans tried to distance themselves from his remarks.
McCain is seeking a sixth Senate term from Arizona and is locked in a tight race.
Questioned on his startling assertion, McCain repeated it: "Directly responsible. Because he pulled everybody out of Iraq, and I predicted at the time that ISIS would go unchecked and there would be attacks on the United States of America. It's a matter of record, so he is directly responsible."
However, McCain later sought to clarify his comments, saying over Twitter: "To clarify, I was referring to Pres Obama's national security decisions that have led to rise of #ISIL, not to the President himself."
Democrats quickly pounced on McCain's criticism. Adam Jentleson, a spokesman for Senate Minority Leader Harry Reid, D-Nev, said McCain's "unhinged comments are just the latest proof that Senate Republicans are puppets of Donald Trump."
Orlando massacre: President Obama meets families of shooting victims
Hindu Sena celebrates 'messiah against Islamic terror' Trump's birthday
Trump hits back at Obama over use of term 'radical Islam'
Would have handed him over to FBI: father of Orlando shooter
REVEALED: Orlando shooter's chilling Facebook posts from inside club