ISTANBUL — The global climate summit in Glasgow was supposed to be a big moment for President Recep Tayyip Erdogan of Turkey. He was expected to use the chance to show off a new embrace of climate issues, and there are few things he likes more than mingling on the international stage beside other world leaders.
But there is nothing he likes less than feeling belittled. Learning that he could not have his large security detail at Glasgow — security has been an obsession since a failed coup against him in 2016 — when the American president was allowed one, seems to have enraged Mr. Erdogan enough for him to cancel his appearance abruptly.
Not going to the climate talks, known as COP26, might have seemed self-defeating, given his recent green pivot, but Mr. Erdogan tried to play to his home base and cast his turnaround as a matter of honor.
“We never allow our country’s reputation or honor to be damaged anywhere,” he said in remarks to journalists on the flight home from Europe. “One more time we showed that we can establish a fair world only with a more equitable approach.”
Unpredictable, combative, politically astute, Mr. Erdogan has been in power for 18 years by always knowing which buttons to push. Yet he is politically vulnerable these days, more so perhaps than at any time in his career.
The president is sliding in the polls as the economy stumbles. Last month, the lira hit a new low against the dollar. Unemployment among his supporters is rising. Inflation is galloping at nearly 20 percent. Increasingly, Mr. Erdogan finds himself on his back foot in the face of a vibrant, unified opposition.
Determined to become modern Turkey’s longest-serving ruler by winning re-election in 2023, Mr. Erdogan is showing signs of growing frustration, as his usual tactics are not working and voters, especially young people eager for a change, grow restless.
“I think he is worried, and afraid of losing power, and it seems to be a plausibility, even to him, for the first time in many years,” said Soner Cagaptay, the director of the Turkish research program at the Washington Institute.
“He has been in office for too long, nearly two decades,” Mr. Cagaptay added. “He is suffering from establishment fatigue, simply too tired to be on top of his game and of the opposition all the time.”
As Mr. Erdogan’s grip on power turns shaky, some analysts warn that the Turkish president may become even more unpredictable as elections approach.
In particular over the past decade, Mr. Erdogan has used foreign policy as a tool to burnish his image at home, said Sinan Ulgen, chairman of the Center for Economics and Foreign Policy Studies in Istanbul.
He has in turn insulted foreign leaders, presented himself as a champion of the Turkish diaspora and of Muslims worldwide, and notably last year projected Turkey’s military muscle in a series of interventions abroad.
He pursued military operations in Syria, Libya, and Azerbaijan and stirred tensions with Greece in the Eastern Mediterranean by sending out drilling ships to explore for gas.
Since last November, however, when he fired his son-in-law as finance minister, the dire state of the Turkish economy has led Mr. Erdogan to soften his stance internationally, dialing back on the rhetoric, Mr. Ulgen said.
“The main issue now is to prevent, or pre-empt, tension so the economy can rebound,” he said.
But Mr. Erdogan has accumulated so many powers that his whims carry the day, and he seems not always to be able to help himself. He reverted to his old tactics in the last couple of weeks, ignoring his closest advisers, and threatening a diplomatic crisis in a show of strength for his supporters.
When 10 Western ambassadors issued a statement calling for the release of a jailed Turkish philanthropist, Mr. Erdogan railed against them for interference in Turkey’s affairs and threatened to expel them all. Then just as suddenly he backed down.
“He went against his own best interests and also against the best counsel from his most trusted advisers and that’s what makes me think that he is not on top of his game anymore,” Mr. Cagaptay said.
The expulsion of the ambassadors was narrowly averted after frantic diplomacy, in time for Mr. Erdogan to meet President Biden on the sidelines of the Group of 20 meeting in Rome, only to have Mr. Erdogan create another fuss over security protocol at Glasgow.
It was yet another display of the impetuousness that has become a hallmark of Mr. Erdogan’s relations with the world, risking major upsets with international partners in a sometimes dubious, increasingly desperate, effort to lift his domestic standing.
Sensing political opportunity, Mr. Erdogan had recently made a startling climate conversion after years in which Turkey stood out as an environmental laggard.
He renamed his environment ministry as the Ministry of Environment, Urbanization and Climate Change, and offered Mr. Biden a copy of a book on the green revolution for which he had written the introduction.
He had allowed the Paris climate agreement to languish, but then had the Turkish Parliament ratify it on Oct. 6, and he was prepared to announce to the gathering of world leaders that Turkey would aim to be carbon neutral by 2053.
“Climate change is a reality and threatens the future of humanity, so Turkey naturally will have a leading role in such a vital matter,” he said in a televised address in Turkey before the COP26 summit.
Mr. Erdogan’s conversion came after Turkey suffered a bruising summer. The worst forest fires in recorded memory scorched a swath of coastal forestland eight times the size of average annual fires, killing at least eight people. Flash floods killed at least 82 people in the northeast in the heaviest rains seen in hundreds of years. And an outbreak of slime choked sea life in the Marmara Sea.
The disasters gave fresh momentum to support for climate action that had been steadily building — in public opinion, in business circles, among civil society groups and across the political spectrum — over the last year or so.
“All the public opinion polls are showing that now the political parties in Turkey in the next elections will have to address this issue very seriously,” said Bahadir Kaleagasi, president of the Institut du Bosphore, a French association that encourages Turkish relations with France and Europe.
In the end, though, the climate summit went begging. Mr. Erdogan apparently saw more benefit in kicking up a diplomatic fuss over the security protocol than in addressing the gathering. Or, as rumors flew about his health, he needed a rest.
He had, in any case, already obtained what analysts said he really wanted from the weekend: an hour with Mr. Biden on the sidelines of the Group of 20 meeting, a sign of potential improvement in U.S.-Turkish relations that might lift Turkey’s standing in international markets.
After Mr. Erdogan had failed to secure a meeting with Mr. Biden in New York in September during the United Nations General Assembly, a meeting this month with the American president “became the number one issue of the Turkey-U.S. relations,” said Aydin Sezer, a political analyst and former trade official.
The Biden administration, while maintaining pressure on Mr. Erdogan over human rights and the rule of law — Turkey has notably not been invited to Mr. Biden’s democracy summit in December — has made clear that it regards the country as an important NATO ally and strategic partner.
“We may have differences, but we never lose sight of the strategic importance we and our partners hold each to the other,” David M. Satterfield, the American ambassador to Turkey, said at a reception abroad the command ship Mount Whitney, which called in to Istanbul on Wednesday.
But an overriding U.S. concern will be to keep relations with the unpredictable Mr. Erdogan on an even keel, said Asli Aydintasbas, a senior fellow at the European Council on Foreign Relations.
That has meant dialing back the close, if stormy, personal relationship that President Donald J. Trump had with Mr. Erdogan in favor of something a bit more at arm’s length.
“Ankara is simultaneously vulnerable and bellicose,” she said. “Washington’s way of dealing with this duality is distancing itself from Turkey.”
“There is a desire to keep this at this stable level — at least for another year — but given that this is an election year, it may not be so easy,” she added.