“It is our duty to explain to the world that there are modern Lawrences who were fooled by a terror organization,” he said, without saying exactly whom he was talking about.

Ahmet Davutoglu, the former foreign minister, is Turkey’s prime minister. But Mr. Erdogan is the one on the phone with President Obama discussing Turkey’s role in combating the Islamic State while the White House has to remind American diplomats to also include Mr. Davutoglu in discussions between the two countries.

Turkey’s continued refusal to allow the United States to use its bases for airstrikes against the Islamic State’s forces in Syria and Iraq — and insistence that the coalition target the government of President Bashar al-Assad of Syria — has laid bare deep divisions between the two countries that have prompted analysts to question Turkey’s reliability as an ally, and some have even suggested that Turkey be expelled from NATO.

The relationship with Washington has long been uneasy. In 2003, Turkey denied the United States the use of its territory to invade Iraq. In 2010, the Turks infuriated Washington by voting against United Nations sanctions on Iran for its nuclear program, and by working with Brazil to broker a proposed deal with Iran.

Early in his career, as mayor of Istanbul, Mr. Erdogan was jailed for reciting an Islamic poem in public. In his early years as prime minister, with the Turkish military still safeguarding the country’s secular order, he kept in check his desire for a greater role for religion in public life, while pushing for membership in the European Union, a pursuit that is now stalled.

In more recent years, with the military having been neutered through a series of sensational trials, he has become a more overtly Islamist leader. In the wake of the Arab Spring uprisings, Turkey sought to play a greater role in shaping regional affairs, supporting Islamist movements, such as the Muslim Brotherhood, which was voted into power in Egypt, and then ousted, dealing a painful blow to Turkey’s ambitions.