ISTANBUL — He didn’t get everything he wanted.
For weeks, President Recep Tayyip Erdogan of Turkey has been trying to undermine his regional rival, Crown Prince Mohammed bin Salman of Saudi Arabia, with a skillful drip of intelligence leaks linking the prince to a gruesome crime: the killing of a dissident, Jamal Khashoggi.
President Trump’s statement on Tuesday made clear that the United States would stick with its Saudi ally, leaving Mr. Erdogan’s biggest ambition — sidelining his rival and realigning American policy in the Middle East — unfulfilled.
“This is not credible,” Numan Kurtulmus, the deputy chairman of Mr. Erdogan’s political party, told reporters on Tuesday, dismissing Mr. Trump’s explanation that no one really knew who was responsible for ordering Mr. Khashoggi’s death as “comic.”
But that does not necessarily mean Mr. Erdogan lost the geopolitical battle over the consequences of the killing.
If anything, the Turkish president may now be in a better position than he was when Mr. Khashoggi disappeared inside the Saudi consulate in Istanbul seven weeks ago.
Mr. Erdogan, who has been widely criticized for locking up more than 100,000 people since an attempted coup two years ago, has gained badly needed international stature from the case. He has successfully claimed the moral high ground vacated by the American president, and he has kept up the pressure on Saudi Arabia.
“He is standing with the overwhelming majority of people in the Arab world,” said Asli Aydintasbas, a senior fellow with the European Council for Foreign Relations. “People are outraged, and they do think that Erdogan is on the right side.”
“Across the Arab world, there is real appreciation for what Erdogan stands for,” she added. “That’s what he cares about and that’s what is important to him.”
Beyond that, the Khashoggi case has allowed Mr. Erdogan to soften his authoritarian image in the West and potentially build some momentum toward repairing deeply strained relations with the United States.
By steadily spooling out grisly details of the killing, Mr. Erdogan has found common cause with American lawmakers outraged by Saudi Arabia’s brazen tactics. Before that, some American politicians were more focused on castigating Turkey, a fellow NATO member, for backsliding on democracy and purchasing an antimissile defense system from the Russians.
“The main benefit has been with Erdogan earning political capital in Washington, which will be useful,” said Sinan Ulgen, a former diplomat for Turkey and the chairman of the Center for Economics and Foreign Policy Studies in Istanbul.
Even if he failed to cause a shift in policy within the Trump administration, Mr. Erdogan is unlikely to let the Khashoggi case go. Turkey has called for a United Nations inquiry into the killing and continues to demand answers, if only to clip the wings of the Saudi prince, whom Mr. Erdogan sees as a threat.
At the height of the affair, Turkish officials were calling on Washington to shift its alliances in the Middle East, hoping to nudge the United States away from the powerful monarchies of Saudi Arabia and the United Arab Emirates, as well as from the secular military leadership of Egypt.
Turkey has squared off with Saudi Arabia on a number of fronts, including the kingdom’s dispute with Qatar. Mr. Erdogan’s government also opposes American sanctions on Iran, putting it directly at odds with the Saudi crown prince, often known by his initials, MBS, who described Turkey as part of a “triangle of evil.”
“It was a far-fetched idea that Trump would drop MBS,” said Mr. Ulgen. “There will be some disappointment in Ankara, but also realism.”
In fact, Turkey expected Mr. Trump’s position from the start, argued Ms. Aydintasbas.
“Erdogan is a smart politician and has been around a long time,’’ she said. ‘‘He can see where Trump is coming from,” she added. “They seem to agree to disagree.”
Despite the continuing anti-American sentiment often used by the Turkish government, there are signs that both sides want to repair relations.
“You can see a desire in Ankara to normalize relations with the U.S.,” Ms. Aydintasbas said. “There is also a clear desire on the side of Trump to fix relations with Turkey. Erdogan does not want to ruin that.”
The release last month of an American evangelist pastor, Andrew Brunson, eased Mr. Erdogan’s relations with the White House and with Congress, allowing them to move forward on other disputes that have brought relations to an all-time low over the past year.
Already, Washington has signaled it is doing more to investigate a Pennsylvania-based preacher, Fethullah Gulen, whom Turkey accuses of instigating the attempted coup in 2016.
The two nations have also begun joint patrols in Manbij, in northern Syria, where Turkey and the United States have been at loggerheads. Washington supports Kurdish forces in the region, but Turkey considers them a grave security threat.
On Tuesday, Turkey’s foreign minister, Mevlut Cavusoglu, indicated some acceptance of Mr. Trump’s decision to side with Saudi Arabia, without backing away from the Turkish position that whoever ordered the killing should be revealed.
Many countries did not want to fall out with Saudi Arabia over the murder, he said. “We do not want that either, yet the murder should be brought to light,” he said, according to the semiofficial Anadolu news agency.
Mr. Cavusoglu was in Washington on Wednesday for scheduled meetings to address several of the outstanding disputes between the two countries. Those include an impending fine on the Turkish state bank, Halkbank, for violating American sanctions on Iran, as well as Turkey’s detention of American citizens and three Turkish consular employees on charges of terrorism, which American officials call baseless.
Then, there is the important front in Syria.
Mr. Erdogan rails constantly against the United States’ support for Syrian Kurdish fighters, whom he considers an extension of the Kurdistan Workers’ Party, which Turkey, the United States and Europe have all designated a terrorist organization.
While those issues remain between the countries, Mr. Erdogan is unlikely to waste the political capital he has gained through the Khashoggi case, political observers in Turkey said.
He still can threaten to release the audio recordings of the killing, which Turkish officials have said indicate high-level Saudi involvement. But analysts say that is a “nuclear option” he is unlikely to use, since it would essentially end his leverage.
On Wednesday, in a speech at the presidential palace in Ankara, Mr. Erdogan pointedly did not mention the Khashoggi case or Mr. Trump’s statement of support for the Saudi crown prince.
Instead, the Turkish president was already in full campaign mode for local elections in March, showing that national political concerns still come first as he listed his latest enemies of the state.
He slammed the European Court of Human Rights for a decision calling for the release of a Kurdish political leader, Selahattin Demirtas.
He denounced an imprisoned philanthropist, Osman Kavala, who has been swept up in his post-coup crackdown.
He thundered against wholesalers, whom he accused of raising the price of onions and potatoes.
His nationalist stance has to be seen in the light of local politics, Mr. Ulgen said.
Turkey’s economic difficulties, including a drastic fall in the lira and high inflation, mean Mr. Erdogan’s Justice and Development Party risks losing some important municipalities in March.
“The members of the project to make Turkey kneel down, to make our country surrender, are still in solidarity,” Mr. Erdogan roared, referring to the supporters of popular protests in Gezi Park and Taksim Square in 2013.
“Those praising Gezi, weren’t they the ones who destroyed all the windows, burned everything around? Didn’t they burn the buses belonging to the state? Didn’t they burn down the artisans’ shops? Shall we tolerate them?”