Mattis made the one-day visit after stopping in Iraq to review progress in the campaign against the Islamic State.
Mattis made the one-day visit after stopping in Iraq to review progress in the campaign against the Islamic State group, urging coalition partners to prevent other political issues from disrupting the growing momentum against the jihadists.
He met with Erdogan at the presidential palace after talks with Defence Minister Nurettin Canikli in Ankara.
Turkey, an important NATO ally of the United States and part of the coalition fighting the IS militants, is incensed that Washington has been arming the Kurdish People's Protection Units (YPG) in the assault on the jihadists' stronghold of Raqa, in northern Syria.
Turkey regards the YPG as the Syrian affiliate of the outlawed Kurdistan Workers' Party (PKK), but Washington has been impressed with its ability to combat IS on the ground.
In May, the Pentagon said it had begun transferring small arms, including AK-47s, and vehicles to the YPG to support its role as a leading player in the Syrian Democratic Forces (SDF), a Kurdish-Syrian Arab alliance fighting IS.
During the meeting, Erdogan told Mattis that Turkey was "uneasy over the US support" for the YPG, presidential sources said.
The Pentagon said Mattis addressed Turkey's "legitimate" security concerns in the meeting and both men expressed a shared interest for their countries "to create conditions for a more stable and secure region."
Erdogan has repeatedly vowed that Turkey will thwart any attempt by the YPG to carve out a Kurdish state in northern Syria, leaving open the possibility of a cross-border operation to prise the town of Afrin from Kurdish control.
"Turkey will not allow a terror corridor reaching the Mediterranean in northern Syria," Erdogan told reporters on his plane back from a visit to Jordan.
"Whatever the price, we will conduct the necessary intervention," he said, quoted by the Hurriyet newspaper on Wednesday.
Last August, Ankara launched a cross-border operation in northern Syria aimed at clearing the border zone of both YPG fighters and jihadists.
Complaining about Washington's arming of the YPG, Erdogan said up to 1,000 trucks had crossed from Iraq to Syria carrying weapons for the SDF, which Turkey fears will reach the PKK.
The rise of jihadists in the Syrian northwestern province of Idlib has also caused concern in Ankara, Moscow and Tehran.
Erdogan alluded to plans for Idlib, controlled by the Hayat Tahrir al-Sham jihadist alliance, but would not elaborate, only saying: "What is there now? There is Idlib."
US officials said Tuesday that the grinding fight was the "priority" in the campaign against IS since the fall last month of Mosul, the jihadists' Iraqi hub.
The Kurdish regional government in northern Iraq -- whose peshmerga security forces are playing a key role in the fight against IS -- is planning its own independence referendum in September.
But at the date approaches, the plan is fuelling increasing discomfort in the region.
Mattis met Tuesday with Iraqi Kurdish leader Massud Barzani in Erbil to express US opposition to the referendum.
Erdogan and Mattis reaffirmed their opposition to the vote, Turkish presidential sources said on Wednesday.
And Turkish Foreign Minister Mevlut Cavusoglu, in Baghdad to meet Iraqi Prime Minister Haider al-Abadi and other Iraqi officials, reiterated Turkey's opposition to the "wrong" decision to hold the referendum.
Cavusoglu also held talks with Barzani in Arbil.
The US is concerned at signs of warming ties between Iran and Turkey, whose relationship in the past has been far from straightforward.
The Pentagon said Mattis and Canikli discussed "concern over Iran's malign influence in the region", without giving further details.
Iranian armed forces chief General Mohammad Hossein Bagheri visited Turkey last week, with both sides agreeing to step up regional security and oppose the Kurdish referendum.
Erdogan on Monday said a joint operation with Iran against Kurdish militants based in Iraq was "always on the agenda", but Iran's Revolutionary Guards denied the claim.