The coup against Egypt’s elected president is causing unease among some leaders in the Middle East region who fear a similar fate. One of them, Turkish prime minister Recep Tayyip Erdogan, is being proactive in preventing his ouster. He has persuaded parliament to amend a rule that the nation’s military has used as justification to stage coups.

On July 13, the Turkish parliament amended the military’s working manual—called the Internal Service Code—to recast how generals respond to a perceived threat. Until now, Article 35 of the code allowed the military to intervene to defend the country against both external and internal threats. From 1960 to 1997, the military used the law as justification to stage four coups. The amendment eliminates military oversight of internal instability, leaving it to defend the country only from outside threats.

It’s hardly surprising that Erdogan, who has adamantly denounced the July 3 ouster of Egyptian President Mohamed Morsi, made the move, given recent domestic protests against his rule.

The move is good politics for the embattled leader, since coups and military involvement in politics are generally very unpopular in Turkey, Ross Wilson, a former US ambassador to Turkey and now with the Atlantic Council in Washington, DC, told Quartz. Over the years, the Turkish population has bristled at military interventions and pushed back once the coups were over. “In pushing for this change in the military’s internal regulations, Erdogan is reminding everyone of this and of his government’s success in getting the military out of politics,” says Wilson.