There were no casualties in the fleeting attack, in which three of the six bullets fired hit the embassy gate and a reinforced window in the building in Ankara.
"We can confirm a security incident took place at the U.S. Embassy early this morning. We have no reports of any injuries and we are investigating," embassy spokesman David Gainer said. He thanked Turkish police for their "rapid response."
Ankara governor's office named the suspects as Ahmet Celikten, 39, and Osman Gundas, 38, saying they had confessed. They were apprehended along with a 9-millimeter gun and a vehicle with Ankara license plates.
The statement said Celikten had escaped prison and Gundas had several crimes under his belt, including car theft, drugs, threats and injury.
Turkish officials are locked in a trade and diplomatic dispute with the United States but they fully condemned the shooting in Ankara. Presidential spokesman Ibrahim Kalin tweeted that it was "an attempt to create chaos."
A top official in Turkey's ruling Justice and Development Party said the attack was a "clear provocation" and that foreign diplomats are guests of the country.
"The utmost sensitivity will be shown to ensure their security," said the party spokesman, Omer Celik. "Turkey is a safe country."
The governor's office said they were investigating the suspects' links.
The U.S. Embassy was planning to close at midday Monday anyway until the end of the week for the Islamic holiday of Eid al-Adha.
Tensions between the U.S. and Turkey are high, partly because of the case of Andrew Brunson, an American pastor who is being prosecuted in Turkey for alleged espionage and terrorism-related offenses. He denies any wrongdoing and U.S. President Donald Trump has called for his immediate release.
Turkey has long criticized the United States for not agreeing to hand over Fethullah Gulen, a Muslim cleric accused by Turkish authorities of engineering an attempted coup in 2016. Gulen denies those allegations. Washington has told Turkey it must present convincing evidence for any extradition proceeding to go forward.
The Turkish lira has lost 39 percent of its value against the U.S. dollar since the beginning of the year and was hurt further by recent U.S. tariffs on Turkish steel and aluminum. Turkey's economy is already vulnerable because of heavy foreign currency borrowing that fueled high growth for years.
Turkish President Recep Tayyip Erdogan, whose government imposed its own tit-for-tat tariffs on some American goods, alluded to the dispute with the U.S. in a pre-recorded holiday message.
"There is no difference between the direct attacks on our call to prayer and our flag and the attack on our economy," said Erdogan. "Those who think they can make Turkey give in with the foreign exchange rate will soon see they are wrong."
U.S. diplomatic offices have been targeted in the past in Turkey.
At least one suspect was wounded in a shooting outside the U.S. consulate in Istanbul in 2015. In 2013, a suicide bomber killed a Turkish guard and himself outside the embassy in Ankara. In 2008, three assailants and three Turkish police officers died in a shootout outside the Istanbul consulate.
Christopher Torchia in Istanbul contributed to this report.