Turkish authorities say a coup by the nation’s military was “foiled” Friday, leaving at least 161 dead and launching the NATO ally's major cities into chaos.

“The situation unfolded in Turkey was a coup attempt to overthrow the democratically-elected government,” the Turkish embassy in the U.S. said late Friday in a statement.

ADVERTISEMENT

“This attempt was foiled by the Turkish people in unity and solidarity. Our President and Government are in charge.”

The embassy said the coup was conducted by a “clique” within the military and not the entire force, adding that it “received a well-deserved response from our nation.”

At least 265 people were killed and 1,440 wounded in clashes as military forces tried to assert control of bridges, TV newsrooms and public areas, ABC News reported, citing Turkish Prime Minister Benali Yildirim.

Among the dead were 104 coup plotters killed, and 2,839 military members were detained. Five generals and 29 colonels were relieved of their duty, the report added.

Turkish president Recep Tayyip Erdogan triumphantly returned to Istanbul early Saturday morning after going to an undisclosed location.

“They have pointed the people's guns against the people," he said of the coup plotters. "This government brought to power by the people, is in charge. They won't succeed as long as we stand against them by risking everything.”

Erdogan vowed to make the plotters “pay,” calling the coup attempt a “gift from god” because it will help remove them from the military.

Erdogan and Yildirim blamed Fethullah Gulen, a Turkish preacher who lives in self-imposed exile in Pennsylvania.

Gulen denied any involvement, saying: “As someone who suffered under multiple military coups during the past five decades, it is especially insulting to be accused of having any link to such an attempt.”

In a statement reported by Buzzfeed, Turkish armed forces on Friday night claimed to “have completely taken over the administration of the country to reinstate constitutional order, human rights and freedoms, the rule of law and the general security that was damaged.”

Coup forces had taken over state-run news network TRT to announce their control over the country at the start of the effort. Soldiers later moved into the offices of CNN sister network CNN Turk in Istanbul and cut the broadcast.

Despite Erdogan's return to Istanbul and officials' declarations that the coup had been quashed, the situation in Ankara, which is about 330 miles away, remained more clouded. Reuters reported that politicians were taking shelter in the Parliament building there, and there were also reports of explosions and gunfire.

President Erdogan arrives at Ataturk International Airport, Istanbul. #resistcoup pic.twitter.com/43nAvpS8E3 — TRT World (@trtworld) July 16, 2016

BREAKING: Large crowds greet President Recep Tayyip Erdogan as he emerges from a vehicle at Istanbul's Ataturk Airport. — The Associated Press (@AP) July 16, 2016

Before his return to Istanbul, Erdogan addressed the country via FaceTime from a secured location in the midst of the coup. He said he did not believe the coup would be successful and urged Turkish people to take to the streets, according to The Telegraph.

“I know no power greater than the power of the public,” he said.

Erdogan making a statement on facetime right now. pic.twitter.com/F1Nip0C01V — Ceylan Yeginsu (@CeylanWrites) July 15, 2016

Images and video showed people flooding the streets of Istanbul and Ankara despite the military forces claiming to have imposed martial law and a curfew. Some seem to be answering Erdogan's call to reject the coup, while others appeared to be cheering military officers and vehicles rolling through the cities.

A state-run news agency, Andalou Agency, reported that an army F-16 had shot down a helicopter controlled by the coup forces and that 17 police officers had been killed in a separate attack by those staging the coup outside of Ankara.

President Obama and Secretary of State John Kerry John Forbes KerryThe Memo: Warning signs flash for Trump on debates Divided country, divided church TV ads favored Biden 2-1 in past month MORE spoke over the phone about the situation, according to a White House release, and urged the support of Erdogan's government.

"The President and Secretary agreed that all parties in Turkey should support the democratically-elected Government of Turkey, show restraint, and avoid any violence or bloodshed," the statement said. "The Secretary underscored that the State Department will continue to focus on the safety and security of U.S. citizens in Turkey. The President asked the Secretary to continue to keep him updated as the situation unfolds."

The head of NATO echoed Obama in a statement of his own, and said Turkey is "a valued NATO Ally."

"I am following events in Turkey closely and with concern," Jens Stoltenberg said. "I call for calm and restraint, and full respect for Turkey's democratic institutions and its constitution."

The United Nations called for calm and said it was likewise monitoring the situation.

Statement from the United Nations on the military coup in Turkey pic.twitter.com/5BICRQ2iqG — BuzzFeed News (@BuzzFeedNews) July 15, 2016

Reports indicated that a contingent inside of the military forces disobeyed commands from on high and attempted to take control of the government, a key NATO ally and bulwark against chaos in neighboring Syria that has struggled to confront a rash of extremist violence in recent weeks.

Two major bridges in Istanbul were blocked by armed forces immediately ahead of Yildirim’s televised remarks, and military jets flew low over Ankara, the capital. It remains unclear whether the efforts were on behalf of the government or the military uprising.

Details remained sketchy, as reports circulated on social media Friday evening that Facebook, Twitter and YouTube had been blocked or slowed down in Turkey.

Twitter's policy account said that that the company had "no reason to think we’ve been fully blocked in #Turkey, but we suspect there is an intentional slowing of our traffic in country."

"We are aware of reports that YouTube is down in Turkey, however, our systems seem to be functioning normally," said a company spokesperson in a statement. "We are aware of reports that YouTube is down in Turkey, however, our systems seem to be functioning normally," said a company spokesperson in a statement. YouTube similarly said it did not believe it had been fully blocked.

A Facebook spokesperson declined to comment.

Turkey has struggled with repeated terror attacks from Kurdish militants and the Islamic State in Iraq and Syria (ISIS) in recent weeks. ISIS staged suicide bomb attacks at the Istanbul airport in March, killing 41 and wounding more than 230.

At the same time, Erdogan has increasingly tightened his grip on the country by sidelining journalists and opposition views, raising concerns about the country’s democratic future.

The U.S. has about 2,200 military troops based in Turkey — in Istanbul, Ankara, and at the Incirlik Airport in Adana, which has been used in the fight against ISIS in Syria. The Pentagon said the coup had "no impact" on the base but raised the security level to "Delta."

The administration ordered families of military personnel based in southern Turkey to return home in March, amid worsening security conditions.

House Homeland Security Committee Chairman Michael McCaul (R-Texas) said on CNN that while tension between the military and Erdogan has always existed, recent ISIS attacks and the presence of Russians in the area could be driving the apparent coup.

McCaul said the "hope" was that those staging the apparent coup were supportive of U.S. efforts in the region, saying a primary concern was an airbase used by the the American Air Force.

"If this movement is about security within Turkey, I would think they would be supportive of our efforts," he said.

Right now in the skies of #Ankara, fighter jets flying low. Please let this be some sort of training, I'm scared. pic.twitter.com/GBOIZL1sNZ — Marina Lourenço (@lourenco_marina) July 15, 2016

Turkish soldiers block both bridges on the Bosphorus in Istanbul and jets flying low in Ankara. Reason not clear yet pic.twitter.com/tMG7KKYvGh — Selin Girit (@selingirit) July 15, 2016

Soldiers shut down the Istanbul bosphorus bridges. Looks like godzilla is coming. pic.twitter.com/LWEruUEU4q — Cagatay Civici (@cagataycivici) July 15, 2016

Live from Turkish TV:

Istanbul Ataturk airport. Many tanks with troops positioned on them. pic.twitter.com/wVD7I6re7C — Gilgo (@agirecudi) July 15, 2016

WATCH: Protesters take over Turkish state-run TV newsroom; atmosphere appears celebratory https://t.co/J54RiATgwT https://t.co/Bh30RFeiLe — CBS News (@CBSNews) July 15, 2016

Updated at 6:42 a.m. on July 16