Three years ago, Egypt's military carried out a swift and successful coup, ousting a conservative Muslim ruler and party that had been elected. A part of Turkey's armed forces attempted a very similar overthrow on July 15.
In both countries, the two most populous in the region, democracy suffered a setback in the wake of the military actions.
The parallels mostly end there.
In Turkey, the coup failed in part, it seems, because of the country's long and often bitter history of military takeovers. Both supporters and opponents quickly united behind President Recep Tayyip Erdogan. They heeded his call and took to the streets, fending off army tanks, knowing the perils of military rule in decades past.
Even Erdogan's political enemies fell in line, condemning the attempted coup. It was bloody, with more than 260 killed in a night of fighting between the military and opponents of the coup, but by the following day, it was over.
"The entire political class committed to civilian supremacy and firmly rejected any role of the military in civilian politics," said Michael Wahid Hanna, a senior fellow at the Century Foundation based in New York. "Turkey, for all its problems, has a relatively successful political system."
Many older Turks have unpleasant memories of life under military rule, while many younger citizens appeared protective of the country's democracy. While there are many critics of Turkey's political system, it has held regular, contested elections for decades. Erdogan and his Justice and Development Party have won multiple ballots during their 13 years in power.
That stands in sharp contrast to Egypt, where in the summer of 2013 protesters filled city squares demanding the ouster of the elected president, Mohamed Morsi, leader of the Muslim Brotherhood.
Morsi and his movement had ruled for barely a year. The party took nearly half the parliament seats in the first free and fair elected legislature in Egypt's history and Morsi got the votes to become president. But soon after the election in 2012, Morsi and the Muslim Brotherhood alienated political allies and failed to take control of the state, which viewed him as an enemy.
When the protests began, Morsi and the Muslim Brotherhood were isolated, state institutions and much of Egypt's political class backed the armed forces. The military easily took over, filling Egypt's jails, first with Muslim Brotherhood members and supporters and then many other dissidents.
"In Egypt there was no political process, no consensus, no solidarity among the political class," Hanna said. "People saw their political enemies as much more of a near-term threat than the military. The military was seen as the ultimate arbiter."
Erdogan had quarreled with the military for years and had reduced its power, something that didn't happen in Egypt. And the latest developments have only added to the already troubled relations between Turkey and Egypt.
Egypt's newspapers prematurely declared Erdogan overthrown. One state newspaper in Egypt proclaimed: "A military coup in Turkey. The military announced it has taken charge to protect democracy and human rights, Erdogan calls on citizens to go down to the streets to protect 'legitimacy.'"
The tension between the two states seems likely to continue. Even before the coup attempt in Turkey, Erdogan looked at Egypt and saw it as a cautionary tale about what could happen to him and other religiously conservative parties rising to power through elections.
"President Erdogan has long seem himself as a natural ally of the Muslim Brotherhood throughout the Middle East," said Hugh Pope, Turkey expert at the International Crisis Group. "Any action against the Muslim Brotherhood he saw as a threat to himself."
In a recent interview with Al-Jazeera, Erdogan slammed Egypt's Abdel-Fattah el-Sissi, who as the head of the military led the 2013 coup and then went on to become president.
"Sissi is a coup plotter, just like the people we have here in Turkey now," Erdogan said. "Sissi used weapons and arms to topple Morsi, who was democratically elected. How can this behavior be respected? Thousands of people have been killed; how can this be respected? He has nothing to do with democracy."
Egypt hit back, calling it an attack on its leadership and describing the ouster of Morsi as a "people's revolution" rather than a coup.
Crackdowns in both countries
While the two countries trade jabs, they do share something else in common: Both current leaders have waged extensive crackdowns.
In Turkey, more than 13,000 people have been detained in just over a week, from teachers to police officers to journalists. Tens of thousands of others have been tossed out of their jobs on suspicion of loyalties to Fethullah Gulen, a popular Turkish cleric in his mid-70s who has been living in eastern Pennsylvania since 1999. Erdogan has accused him of plotting the coup.
The pair were once political allies before the relationship soured. Gulen vehemently denies planning the military takeover and condemned the coup attempt.
While Erdogan is trying to eradicate Gulen loyalists, Egypt's Sissi has systematically sought to eradicate the Muslim Brotherhood.
Amnesty International says it's the worst moment for human rights in Turkey since a military dictatorship in the early 1980s. That lasted three years, with around a half-million people arrested and hundreds who died in jail.
The human rights group says interrogators are focused on political affiliations rather than involvement in the coup.
Erdogan has been accused of authoritarian tendencies in the past and has been steadily concentrating power. But he's also loved by many supporters for ushering in economic growth and working toward European Union membership.
However, Turkey was facing a host of challenges even before the coup attempt, with bombings blamed on ISIS or Kurdish militants inside Turkey, a renewed battle with Kurdish separatist groups in the southeast of the country, a huge Syrian refugee population and an economic downturn.
"President Erdogan is a pretty cunning political operator who may have an Islamist upbringing, as it were, and worldview, but he's quite an opportunist," Pope said. "Turkey desperately needs some rebalancing in the Middle East. "
Support the news
More NPR or Explore Audio.