Turkey has begun a purge of soldiers and judiciary officials allegedly connected to an effort to topple the government, one day after a  failed military coup attempt.

By Saturday evening, the government of President Recep Tayyip Erdogan had detained 2,839 military personnel, with the number of arrests expected to rise, according to Prime Minister Binali Yildirim.

Turkey's top judicial body, the HSYK, dismissed 2,745 judges on Saturday, according to Turkey's Anadolu news agency.

Additionally, a senior Turkish official told Al Jazeera that at least two judges from Turkey's constitutional court and 10 judges from the HSYK had been detained.

Turkey: Crowds attack troops after coup attempt

Speaking on condition of anonymity, the official said that the judges were detained based on "financial transactions and communications between the individuals in question and the putschists", but added that detention did not necessarily mean conviction.

Another senior official, also speaking anonymously, told Al Jazeera that a top army general was also detained over his alleged involvement.

Turkey's government vows to 'cleanse' military after failed coup

"General Erdal Ozturk, commander of the Third Army, has been detained," he said.

"Our sense is that the would-be junta had made preparations for some time. They had determined which military officers would take over as governors, heads of government agencies ... but they were forced to rush due to the upcoming Supreme Military Council meeting," he added.

The coup attempt began at around 19:30 GMT on Friday with the partial closure by troops of two major bridges over the Bosphorus in Istanbul.

"Their immediate goal was to seize control of key areas like the Bosphorus Bridge or Taksim Square. In Ankara, they tried to storm the Presidential Palace, the Prime [Minister's office], the National Intelligence Organization and the Parliament. They also attempted to take down the satellite infrastructure and, in some areas, seized control of telecommunications hubs."

Another official told the Associated Press news agency that Ozturk was one of the "masterminds of the coup".

Coup attempt quashed

A total of 265 people were killed in the attempted coup that played out overnight across Turkey, Yildirim said earlier Saturday, among them 161 government forces and civilians.

Defence Minister Fikri Isik said on Saturday that the coup attempt had been quashed and that no area was out of the government's control.

But Isik also told reporters that it was too early to say if the threat of the coup was completely eliminated, and urged government supporters to take to the streets again. 

"Systemic operations are complete" but mopping up measures could still take hours, Hakan Fidan, head of the country's National Intelligence Organization, said, according to a government official.

As a sign of defiance and a rare show of unity across party lines, Turkey's parliament convened in Ankara in the parliament building that had been damaged during the coup attempt.

Members of all four political parties represented in the parliament - which all opposed the coup attempt - attended the session.

The opposition used the opportunity to call for a strengthening of democracy in the country.

Erdogan demands extradition of Gulen

Erdogan has blamed the coup attempt on US-based religious leader Fethullah Gulen, an Islamic preacher and one-time ally who fell from Erdogan's good graces for allegedly orchestrating a corruption scandal in 2012 and running a "parallel state".

In Istanbul on Saturday, Erdogan urged the United States to extradite the preacher.

"The United States, you must extradite that person," he told thousands of supporters.

Gulen told reporters on Saturday in Pennsylvania that the attempted overthrow may have been staged, and urged the Turkish people not to view military intervention in a positive light.

Turkey's coup attempt captured in dramatic images

"There is a slight chance, there is a possibility that it could be a staged coup," he said. "It could be meant for court accusations and associations."

Gulen said democracy cannot be achieved through military action, but criticised the Erdogan government.

"It appears that they have no tolerance for any movement, any group, any organisation that is not under their total control," he said.

Military aircraft in Turkey were hijacked by so-called coup plotters during the overnight events and, according to government officials, used to attack key buildings, including the parliament building.

People took to the streets of Istanbul on Saturday, lining the sides of major roads and holding the red and white Turkish flag in support of the civilian government.

"I welcome the strong support shown by the people and all political parties to democracy and to the democratically elected [government] of Turkey," NATO Secretary General Jens Stoltenberg wrote on Twitter.

The Organization for Security and Co-Operation in Europe (OSCE) appealed for restraint.

"All those that carry responsibility must adhere to the rules of democracy and the rule of law and must prevent any further bloodshed," said German Foreign Minister Frank-Walter Steinmeier, who serves as chairman of the OSCE.

Amnesty International urged Turkey not to use the death penalty against detained putschists after government supporters chanted during demonstrations for the use of capital punishment.

The attempted coup was carried out by "a group within the military" acting "outside of the chain of command", the president's office said earlier in the day.

Source: Al Jazeera and agencies