ISTANBUL — Turkey’s prime minister, president and military chief gathered Thursday in an emergency meeting aimed at defusing a political crisis that is threatening the stability of the country.

The meeting in Turkey’s capital, Ankara, lasted several hours and came as three of the country’s highest-ranking former military officers appeared in court in Istanbul for questioning about an alleged coup plot. Those officers — the former heads of the air force and the navy, and a former deputy head of the army — were released late Thursday, according to the semiofficial Anatolian News Agency, a development that is likely to pull the standoff between the military and the government back from the brink of all-out confrontation.

Turkey’s military, broadly respected in Turkish society, used to be considered untouchable. The mere fact that such senior former officers appeared in court was shocking, an unprecedented development that has put Turkey’s long-powerful, secular military on the defensive against the popular political party with Islamic roots that runs the government.

Shortly before the three officers were released, President Abdullah Gul called for calm, assuring Turks in a written statement issued after the meeting that “matters will be handled in line with the constitutional order and law,” and exhorting all involved to “act responsibly and not damage our institutions.”