WASHINGTON — With all the crises in the Middle East, the Obama administration took solace in the fact that there was one reliable, democratically elected strongman — a stalwart member of NATO — that Washington could depend on: President Recep Tayyip Erdogan of Turkey.

No matter how the coup attempt against Mr. Erdogan plays out over the next hours and days, that certainty is shattered.

Until midafternoon Friday, American officials thought Mr. Erdogan had tightened his iron grip on his country. He had purged the judiciary; jailed insouciant senior military officers three years ago and installed seemingly compliant successors; and cracked down on the opposition and the news media.

As one senior American diplomat said Friday evening, no one had come to work that day at the White House, the State Department or the C.I.A. expecting to see Mr. Erdogan turn to FaceTime on his iPhone to plead with the Turkish people to take to the streets in his defense.

Even though the coup attempt appeared to be failing by early Saturday morning in Turkey, the country had suddenly become another tumultuous one in a region that knows no end of turmoil.