Senator John McCain was one of the earliest advocates of American military action against the Islamic State in Iraq and Syria. So it has been vexing for Mr. McCain to be battling persistent — and false — Internet rumors that he not only helped invent the group but also knows its leader, Abu Bakr al-Baghdadi, the self-proclaimed caliph of the Muslim world and America’s latest Public Enemy No. 1.

The rumors are based partly on images of a Syrian fighter who resembles Mr. Baghdadi, seen in photographs with Mr. McCain — some originally posted on Twitter by the senator — during his visit in May 2013 to northern Syria. He met members of the Free Syrian Army, an insurgent group that opposes ISIS and that President Obama, in a speech Wednesday on his new strategy for battling ISIS, has vowed to strengthen.

Nurtured by conspiracy blogposts, social media and photo-altering tricks, the false rumors of Mr. McCain’s relationship with ISIS have taken on a life of their own. One doctored photo shows the senator, an Arizona Republican, pinning a medal on Mr. Baghdadi’s chest.

Last month the rumors received new vitality when a left-leaning American veterans group asserted that the senator had posed for photographs “with ISIS militants.” The rumors were further bolstered with the news that an American recruit to ISIS shared the senator’s surname. And on Wednesday in Iran, where many people already believe ISIS is an American plot to destabilize their country, the state television asserted that Senator McCain was an ISIS cohort. As proof, it showed one of the photographs.