ISTANBUL — As a rebel faction of Turkey’s military began a violent attempt to topple the elected government, the country’s top officer, Gen. Hulusi Akar, was held at gunpoint in his office in the capital and told for the first time about what was happening.

“Sir, the operation is starting,” a coup-plotting officer said, according to General Akar in testimony that was leaked to the Turkish news media and verified by a senior Turkish official as authentic. “We will round up people, battalions. Brigades are on their way. You will see a bit later.”

General Akar replied: “What the hell are you saying? What operation? Are you a maniac? Never!”

The plotters hoped to secure General Akar’s participation in the conspiracy, but his refusal was decisive in ensuring this coup attempt would fail — unlike those in Turkey in 1971 and 1980, which were supported up and down the chain of command.

Now, as President Recep Tayyip Erdogan wages a widespread purge, jailing and suspending tens of thousands of state employees, the military, which has long served as a unifying force for the country, is deeply divided, diminished and discredited. Nearly half of the top generals and admirals have been jailed or dismissed and thousands of foot soldiers charged. More than 1,500 officers were dishonorably discharged this week in advance of a meeting of the Supreme Military Council in Ankara on Thursday, where leaders were expected to consider a broader restructuring of the military.