The diplomat, Mohammed Al-Madadi, was flying from Washington to meet imprisoned Al-Qaeda sleeper agent Ali Al-Marri for a routine consular visit, a State Department official and another person close to the matter said Thursday. Al-Madadi slipped into the plane’s bathroom for a smoke, authorities said, then joked about trying to set his shoe on fire — an apparent reference to would-be “shoe bomber” Richard Reid, who was convicted for his 2001 attempt to down an airliner.

That touched off a major response by security officials still smarting from a nearly disastrous Christmas Day airline bombing in Detroit. The military scrambled fighter jets Wednesday night, and the FBI questioned Al-Madadi for hours.

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 US 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 US that Al-Madadi will leave the country.

Those who discussed the case did so on condition of anonymity because they were not authorized to discuss the matter.

“We fully expect this will be resolved very quickly,” State Department spokesman P.J. Crowley told reporters, adding that the US government is satisfied the Qatari government is taking the matter seriously.

The purpose of Al-Madadi’s trip — meeting with a dangerous terrorist — raises questions about why someone familiar with national security cases would apparently flout airline security rules and joke about would-be bombers.

Al-Marri, a citizen of Qatar, is serving eight years in prison after pleading guilty last year to conspiring to support terrorism. He was arrested after the Sept. 11, 2001, terrorist attacks, accused of being a sleeper agent researching poisonous gasses and plotting a cyberattack.

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

Under international protocol — the 1961 Vienna Conventions on Diplomatic Relations — diplomats in foreign countries enjoy broad immunity from prosecution. That immunity can only be waived by a diplomat’s home government, something that is rarely requested and even more rarely granted.

But even without pressing charges and without such a waiver, the US could have moved to declare Al-Madadi “persona non grata” and expel him from the country.

However, officials said they would not attempt to do so, given the close nature of US-Qatari ties and the importance the country plays in the Middle East.

Qatar, about the size of Connecticut and Rhode Island combined and with a population of about 1.4 million people, is oil-rich and an important US ally.

The country hosts the forward headquarters of the US Central Command, which runs the wars in both Afghanistan and Iraq, and is a major supporter of operations deemed critical to both campaigns.

Qatar’s ambassador to the United States, Ali Bin Fahad Al-Hajri, cautioned against a rush to judgment.

“This diplomat was traveling to Denver on official embassy business on my instructions, and he was certainly not engaged in any threatening activity,” he said in a statement. “The facts will reveal that this was a mistake.”