Tensions between both countries are mounting over trade hostilities and China’s increasingly assertive claims to territory in the South China Sea.
Mr Mattis is the first Pentagon chief to visit China since 2014.
He is on a trip across Asia, meeting several regional US allies.
Mr Mattis said his talks with Mr Xi and other officials in Beijing on Wednesday had been “very, very” good, adding that the US was assigning a “high degree of importance to the military relationship” with China.
Mr Xi added that China had peaceful intentions, but reasserted his view that there would be no concessions from China about what it considers to be Chinese territory.
“We cannot lose even one inch of the territory left behind by our ancestors,” Mr Xi said, according to Chinese state media. “What is other people’s we do not want at all.”
The US has repeatedly criticised China’s movements in the South China Sea, accusing it of intimidating its neighbours and militarising the area, by building up facilities on artificial islands.
Several countries have competing claims in the disputed sea, but China claims the largest portion of territory, saying its rights go back centuries.
The area is a major shipping route, and a rich fishing ground, and is thought to have abundant oil and gas reserves.
The defence secretary’s Asia tour comes after a historic summit in Singapore which saw US President Donald Trump meet North Korean leader Kim Jong-un.
On Thursday, Mr Mattis travelled on to South Korea and met the country’s defence minister Song Young-moo.
Mr Mattis sought to reassure Seoul that the US’s commitment to the region’s security remained “ironclad”.
He said Mr Trump’s recent decision to suspend military drills with South Korea would create “increased opportunity for our diplomats to negotiate, increasing prospects for a peaceful solution on the peninsula”.
President Trump’s move to cancel the joint military exercises, following his meeting with Mr Kim, was seen as a big concession to North Korea and appeared to take US allies in the region by surprise.
North Korea sees the annual exercises as a rehearsal for invasion, but the government in Seoul maintains they are defensive in nature.