General Isik Kosaner, the head of the Turkish armed forces, has quit along with the heads of the ground, naval and air forces.
The country's state-run Anatolia news agency said on Friday that the military chiefs wanted to retire because of tensions with Recep Tayyip Erdogan, the recently re-elected prime minister.
Anatolia reported Kosaner as resigning "as he saw it as necessary".
In a written statement released after the news of the generals' retirement, Erdogan said that the armed forces would continue to do their duty in a spirit of unity.
Erdogan also named General Necdet Ozel, head of the gendarmerie paramilitary force, as both the commander of the ground forces and acting chief of the armed forces. Abdullah Gul, the president, approved the appointment.
Ozel was the only one among the top commanders not to ask for retirement.
He was expected to be appointed as chief of the military's general staff in place of Kosaner, as tradition dictates only the ground forces head can take over the armed forces.
Speaking to Al Jazeera, Yusuf Kanli, a columnist with Hurriyet, a Turkish daily newspaper, said that Kosaner was quitting his post as an act of protest against the court cases jailing military officers, which meant he could no longer defend the rights of his staff.
"However, I do not think that this shows that there is a deepening rift between the government and the army because resignation means leaving the seat to the government. By resigning, they opened the door for the government to make the appointments they would like to make. And indeed, the government immediately stepped in and appointed new army commanders.
"It seems that, in the past, when the military expressed dissatisfaction with the government, the government would leave. Nowadays, when the government expresses displeasure to the top generals, the top generals are leaving. There is a change of rolls," Kanli said.
This is the first time so many top commanders in Turkey have stepped down at once.
Al Jazeera Turk's Elif Ural said Erdogan, Gul and Kosaner met for 50 minutes in the morning, which was the last time the three could meet before next week's Supreme Military Council meeting, where key posts for next year are to be decided.
There were hopes that leaders of the government and the military could reach a compromise about the postings, but the retirement announcements showed the rift could not be bridged, Ural reported.
The mass retirement notices came hours after a court charged 22 suspects, including several generals and officers, with carrying out an internet campaign to undermine the government.
The unprecedented departures come ahead of the annual spring meeting scheduled for August 1, where leaders of the government and the military come together to discuss key appointments for the next year.
Al Jazeera's Anita McNaught reports from Istanbul
Reports say Friday's news signals a deep-rooted rift between the military and the government, amid an ongoing trial accusing dozens of generals and officers for plotting to overthrow the government.
In a 2003 case called the "Sledgehammer", 17 generals and admirals in line for promotion have been jailed along with nearly 200 officers on charges of plotting to over throw the government.
More than 400 people - including academics, journalists, politicians and soldiers - are also on trial on separate charges of plotting to bring down the government.
That case is based on a conspiracy by an alleged gang of secular nationalists called "Ergenekon".
The government denies the cases are politically motivated and says it is just trying to work to improve democracy.
Military vs government
Erdogan's ruling AK party, which won a third term in elections on June 12 in a landslide victory, has said its key goal is to replace a military-era constitution with a more democratic one.
But critics say AK has a secret Islamist agenda, an allegation it denies.
The Turkish military has staged three coups between 1960 and 1980 and forced the country's first Islamist-led government out of power in 1997.
Coup leaders drew on the support of Turks who saw them as saviours from chaos and corruption, but they were often ruthless.
In the 1960 takeover, the prime minister and key ministers were executed and in a 1980 coup, there were numerous cases of torture, disappearance and extrajudicial killing.
Such intervention is no longer regarded as feasible, as the power of the military has been curbed sharply under reforms carried out by Erdogan's government.
Kosaner, who took over as head of the armed forces in August 2010, is regarded as a hardline secularist, but he has kept a lower profile than previous chiefs of the general staff.
The announcement comes amid an upsurge in fighting in southeast Turkey between the military and the separatist Kurdistan Workers Party guerrillas.