DUBAI, United Arab Emirates -- Qatar's behind-the-scenes role in securing the release of U.S. Army Sgt. Bowe Bergdahl in exchange for five Taliban operatives was a classic move by a tiny but natural gas-rich Gulf state with outsize ambitions that extend to hosting soccer's World Cup in eight years' time.
The OPEC member has shown a knack for keeping channels to conservative Islamists open while it curries favor with an array of world powers. For Qatar's ruling Al Thani family, it is a hedge that ensures influence and security in a volatile part of the world.
In this case, Qatar was able to act as a broker because of longstanding links to the Taliban. The Islamic militant movement last year opened a representative office in Qatar, but effectively shut it weeks later following a dispute over its use of the name "Islamic Emirate of Afghanistan" and of a flag flown when it ruled Afghanistan beginning in the 1990s.
It is unclear how many of the Taliban envoys ever left Qatar -- but the foundation had been laid for ongoing talks.
"It's really a continuation of Qatar's strategy of making itself useful to other powerful countries, and helping them sort out their problems," said Christopher Davidson, a specialist in Gulf affairs at Britain's Durham University.
He likened Qatar to an "Arab Switzerland" and doesn't see a contradiction in it cultivating relationships with both the U.S. and Islamist groups.
"They've always tried to keep a foot in both camps," he said. "It's a way of having a response to accusations that Qatar is un-Islamic. ... It can always pull out of the bag that it's one of the few states that have a direct line to Kandahar or Kabul or wherever else."
Qatari Foreign Minister Khalid bin Mohammed al-Attiyah described his country's role in the lengthy negotiations as a humanitarian gesture when asked about it at a press conference this week. He gave away few details, saying only that the trust Qatar enjoys with both sides helped smooth the process along.
American officials have since told The Associated Press that Qatari intermediaries acted as go-betweens for months, including during the final days of negotiations that led to the detainee swap.
The deal that eventually emerged led to the Taliban leaders' quiet arrival in Qatar as an international aviation conference was getting underway following the opening of a sleek new airport in Doha -- and as the country was coming under renewed international scrutiny over its winning but controversial bid to host the World Cup in 2022.
The role of mediator is not new for Qatar.
The emirate was the site of peace talks between Sudanese officials and Darfur rebel groups, and it more recently has hosted gatherings of Syrian opposition groups -- of which it is a major backer -- fighting to oust President Bashar Assad.
At one point it even allowed an Israeli trade office to operate -- before ordering it closed following Israel's 2008 mini-war with the Islamic militant Hamas that ruled the Gaza Strip.
Qatar has worked hard to strengthen its ties to the U.S., including a $100 million pledge in 2005 to help Americans recover from Hurricane Katrina.
It was one of the only Arab countries to provide active military assistance to NATO-led attacks against the regime of Libyan leader Moammar Gadhafi, deploying warplanes while simultaneously shipping cash and weapons to the rebels who eventually toppled him.
The desert outside the capital Doha is home to al-Udeid Air Base, which serves as a major command and logistics hub for American air power in the region. American oil companies including Exxon Mobil have large investments in Qatar's energy industry.
Former Prime Minister Hamad bin Jassim Al Thani wasn't shy about at least part of his country's rationale for cultivating American friendship. According to a 2009 diplomatic cable exposed by WikiLeaks, he responded to American thanks for the Hurricane Katrina donation by noting "we might have our own Katrina" -- apparently suggesting a possible quid pro quo should disaster strike.
Providing a venue for the Americans to negotiate with the Taliban is another way to help a powerful friend in need.
"If they can play an important role in allowing America to exit to Afghanistan ... that strikes me as an enormous carrot," said David Roberts, a Qatar-based Gulf expert at King's College London.
Qatar's actions haven't always been greeted warmly in Washington.
The U.S. government, like many Arab regimes, has had an uneasy relationship with the Qatar-backed pan-Arab TV news network Al-Jazeera. Critics sometimes see its coverage as biased and anti-American -- charges the network denies.
Despite its dalliance with Israel, Qatar has supported the Jewish state's archenemy, Hamas. The former Qatari emir two years ago became the first head of state to visit Gaza since Hamas took over the strip in 2007, and Qatar continues to host Hamas leader Khaled Mashaal.
Other controversial figures who have taken up residence in Qatar over the years include the Egyptian-born cleric Youssef al-Qaradawi, whose fiery sermons have irked Gulf neighbors such as the United Arab Emirates, and Gadhafi's former spy chief Moussa Koussa.
The country in recent months been sidelined regionally over its strong support for Egypt's Muslim Brotherhood. Many of its neighbors, like the new government in Egypt itself, see the Islamist group as a threat. Qatar pumped billions of dollars in aid to Brotherhood-backed Egyptian President Mohammed Morsi before his ouster last year.
Qatar is also dogged by questions over its World Cup plans. Britain's Sunday Times reported over the weekend that it had evidence of $5 million in alleged payoffs by a Qatari official to football officials in support of the bid. The Qatar 2022 organizing committee denied the allegations. The country has also had to fend off charges that its vast numbers of migrant workers face exploitation and dangerous work conditions, and recently outlined plans for labor reforms.