A Turkish court Friday rejected an appeal for the release of Andrew Brunson, the American pastor who has been held since 2016 on terrorism charges the U.S. says are baseless.

Why it matters: President Trump has fumed in recent days over Brunson’s continued detention, slapping sanctions on Turkey and threatening further action. He told reporters today that Turkey had "acted very, very badly" and "we are not going to take it sitting down." The standoff has sent long-simmering tensions with Turkey boiling over, and led to fears the U.S.-Turkey alliance could break down.

The backdrop: "There has been a crisis in U.S.-Turkey relations for a while now," says Soner Cagaptay, Washington Institute fellow and author of "The New Sultan." He says other issues over which "the two sides disagree vehemently" include:

U.S. support in Syria for the YPG, a Kurdish militia that Turkey views as a terrorist group.

a Kurdish militia that Turkey views as a terrorist group. The continued residence in Pennsylvania of Fethullah Gulen — a cleric whom Turkish President Recep Erdogan claims was behind the failed attempt to oust him in 2016.

— a cleric whom Turkish President Recep Erdogan claims was behind the failed attempt to oust him in 2016. Looming punishments for Halkbank, a state-owned Turkish bank accused of helping Iran evade sanctions.

With the standoff over Brunson, however, we have entered uncharted waters. "It went from a crisis in the bureaucracy to a crisis at the presidential level," Cagaptay says.

How that happened...

Trump and Erdogan met on the sidelines of last month's NATO summit, and Trump left under the impression that he and Erdogan had reached a deal: the U.S. would secure the release of a Turkish woman held in Israel, and Turkey would release Brunson.

on the sidelines of last month's NATO summit, and Trump left under the impression that he and Erdogan had reached a deal: the U.S. would secure the release of a Turkish woman held in Israel, and Turkey would release Brunson. But when Brunson was moved to house arrest, rather than released, "Trump felt slighted, and took it personally," Cagaptay says.

rather than released, "Trump felt slighted, and took it personally," Cagaptay says. Trump has now pushed things to the brink, demanding Erdogan's full surrender. "There will be no normalization of relations now without Brunson’s unconditional release," according to Cagaptay.

Erdogan might still have a way out. He could release Brunson, Cagaptay explains, but use his control over the media to frame the move as part of a wider deal that doesn't actually exist.

So why hasn't he done it? Originally, Erdogan wanted to use Brunson as leverage to reduce the punishment on Halkbank and discourage further investigation of the bank by the Treasury Department. Now he's in a bind, but one that has a silver lining.

"Erdogan didn’t want this crisis with Trump, but now he’s looking at how he can intertwine it with the other crises he faces," most notably the long-anticipated economic meltdown which Erdogan is now blaming on U.S. sanctions, despite having largely caused it with his own economic policies.

but now he’s looking at how he can intertwine it with the other crises he faces," most notably the long-anticipated economic meltdown which Erdogan is now blaming on U.S. sanctions, despite having largely caused it with his own economic policies. "Erdogan is a master of turning situations to his advantage," Cagaptay says. "His base buys into his rhetoric on this, that other countries don’t want Turkey to be a great power."

What to watch: Both leaders have been have been shocked at various stages here, says Aaron Stein of the Atlantic Council — Trump that Brunson wasn't released despite his efforts to "buddy up" to Erdogan, Erdogan that his long-term bet that no U.S. president would risk losing Turkey as an ally has been called.

"They made a bet on the old rules with the new guy."

— Stein on Turkey's decision to continue to hold Brunson

The bottom line: "Political ties will remain tense until Erdogan finds a way to release Brunson and sell it in Turkey," Cagaptay says, though he isn’t expecting the U.S.-Turkey alliance to collapse entirely. "Military and intelligence cooperation remains strong. That could be the foundation of a reset when it eventually comes."