At least 42 people -- mostly police officers -- were killed in Ankara in a gunfire exchange with a helicopter near the parliament complex, Turkey's NTV reported, citing the attorney general's office.
In Istanbul, a defiant Erdogan addressed crowds in the city, telling them that the coup had been quashed.
"The government is in control," he told supporters as they chanted his name.
"Fifty percent of the people elected the President and that President is on duty," he said.
"My brothers, I want you to know this: Those who brought these tanks out -- what happened to these tanks? My people took these tanks back, haven't they? So far as we believe, so far as we're alive, we'll be prepared to die in the cause to tackle these people. But we will stand firm, we're not going to compromise."
The alleged plotters have not released any statement.
At least 754 people have been arrested in connection with the attempted coup, state-run Anadolu agency reported, citing the interior ministry.
Shortly after dawn, video footage showed soldiers surrendering in masses. They walked away from tanks and abandoned their posts on the Bosphorous Bridge, which crosses the river t Istanbul.
Turkish Airlines resumed flights out of Ataturk, which had earlier been overrun by protesters.
Overnight, opposition soldiers had attempted to seize control in various locations across the country, including the capital Ankara.
Erdogan traveled overnight from the seaside resort of Marmaris and addressed the country Saturday from Istanbul's Ataturk airport. He called the attempt "treason."
Erdogan took the forces he apparently suspects of masterminding the coup to task.
"Now I'm addressing those in Pennsylvania," he said, in an apparent reference to Fethullah Gulen, a cleric and former ally who lives in exile in Pennsylvania.
"The betrayal you have shown to this nation and to this community, that's enough. If you have the courage, come back to your country. If you can. You will not have the means to turn this country into a mess from where you are."
The Alliance for Shared Values, which is connected to the cleric, denied that it was involved.
"We condemn any military intervention in domestic politics of Turkey," the group said in a statement.
Witness Katherine Cohen, an American who's staying in an Istanbul hotel, told CNN she heard a loud explosion as the sun rose, and gunfire and jets all through the night.
For much of the night, fighter jets flew low over Istanbul while armored vehicles streamed across a main bridge in the city. Gunshots rang out on that Bosphorus Bridge, sending pro-government protesters down to the ground.
In Ankara, gunfire was heard overnight throughout the city and jets circled above.
"When I stuck my head out, I could see helicopters shooting," Diego Cupolo, a photojournalist in Ankara told CNN.
He said he could see tracer rounds zip through the air.
Bombs were thrown at the Parliament building in the capital Ankara. A helicopter the government says was stolen by coup plotters was shot down by an F-16.
The United States, United Kingdom and other nations are watching the crisis intently to see what will happen in Turkey -- a member of the NATO Western military alliance, and home to air bases used in the fight against ISIS in Iraq and neighboring Syria.
Chaos in the streets
Tens of thousands of protesters took to the street after Erdogan's call to confront the military was broadcast on television. Many waved Turkish flags and they chanted their support for the President. Some climbed on tanks, some blocked the path of military vehicles with their cars. But some soldiers got hugs from apparent supporters.
Ömer Çelik, Turkey's EU negotiator, tweeted images that he said showed some of the damage at the Turkish Parliament:
"Our country has been subjected to treacherous enemy attack, which displays betrayal to the nation, their uniforms and morals. The necessary response has been shown to the enemy and it is still being shown," he said.
A fighter jet shot down a helicopter that had been commandeered by "coup plotters," a Turkish presidential source told CNN.
There were reports of gunfire, according to Turkish broadcaster IHA and the U.S. Embassy in Ankara.
The Turkish military claim of a takeover was read by an anchor on state broadcaster TRT. She said the military imposed martial law.
The statement was made on behalf of the "Peace in the Nation" council, the announcer said. "The political administration that has lost all legitimacy has been forced to withdraw," the anchor said. Later, after the military was kicked out, she said she was forced to read the military statement. "We were taken over. I was forced by men with arms and they told us that they would not harm us if we did as told."
When the coup began, soldiers blocked two bridges in Istanbul between the European and Asian sides.
Erdogan said law enforcement was arresting military officers of various ranks amid the ongoing military coup attempt. Speaking from Istanbul Ataturk Airport, Erdogan said the hotel he was visiting in the seaside province of Marmaris was bombed after he left.
Unclear who is in charge
Earlier, Prime Minister Binali Yildirim vowed the coup attempt would not succeed.
He told state news agency Anadolu the coup is "an attempt against democracy and the will of the people. Those who attempted this will pay the heaviest price."
A CNN producer said that as the protests began there were 200 to 300 residents in Taksim Square in Istanbul. Many of them were waving Turkish flags. About 100 police officers were shooting off tear gas, trying to disperse the crowd.
The U.S. Embassy said in a statement: "We urge U.S. citizens to contact family and friends to let them know you are safe. We have seen reports that social media is blocked ... We encourage U.S. citizens to shelter in place and do not go the U.S. Embassy or Consulates at this time."
Secretary of State John Kerry spoke with Turkey's Foreign Minister Mevlut Cavusoglu and "emphasized the United States' absolute support for Turkey's democratically-elected, civilian government and democratic institutions."
Erdogan came to power in 2003
Erdogan is the co-founder of Turkey's ruling Justice and Development Party (AKP). He was elected Prime Minister in 2003. Under his rule, Turkey became a powerhouse in the Middle East. His reign came to an end in 2014, and his own party's rules prevented him from seeking a fourth term.
So, he ran for president -- and won. Before this, the president of Turkey was a largely ceremonial role, but Erdogan tried to change that by altering the constitution to give him more power.
Under Erdogan, who is extremely conservative, religion had started to play a more important role in Turkey, which is a largely secular country. He was active in Islamist circles in the 1970s and 1980s.