WASHINGTON -- A Qatari diplomat was on his way to an official visit with an imprisoned al-Qaida sleeper agent when he touched off a bomb scare by slipping into an airline bathroom for a smoke, officials said Thursday as the diplomat prepared to leave the United States.

The diplomat, Mohammed Al-Madadi, was going to pay a consular visit to the prisoner, said a State Department official and Alison Bradley, a public relations executive hired to speak for the Qatari Embassy.

The prisoner, Ali al-Marri, a citizen of Qatar, is serving eight years after pleading guilty last year to conspiring to support terrorism.

Al-Marri was arrested after the Sept. 11, 2001, attacks and accused of being a sleeper agent researching poisonous gasses and plotting a cyberattack. He was held for nearly six years in the Charleston Naval Consolidated Brig in Hanahan.

Consular officials frequently visit foreigners held in the United States to make sure they are being treated well.

Bradley said Qatari diplomats have made multiple visits to al-Marri in prison since he pleaded guilty. The right to such visits is guaranteed by international agreements, and the U.S. Bureau of Prisons had approved this visit by Al-Madadi in advance, Bradley added.

Questions remained about why a diplomat on an official trip apparently would flout airline security rules.

Law enforcement officials said Al-Madadi later joked that he had been trying to light his shoe -- an apparent reference to the 2001 so-called shoe bomber, Richard Reid.

The American officials who discussed the case did so on condition of anonymity.

No explosives were found on the plane, and authorities said they don't think Al-Madadi was trying to hurt anyone during Wednesday's scare. He enjoys diplomatic immunity from U.S. prosecution and will not be criminally charged, authorities said.

The State Department official said Qatar had not yet informed the administration how it will handle the case but has assured the United States that Al- Madadi will leave the country.