The United States and South Korea have agreed to settle their differences on trade.

The South Korean government said Monday that the two countries had struck a deal on a new version of the free trade agreement that has linked the two economies for the past six years.

South Korea has also secured a partial exemption from President Donald Trump's new steel tariffs.

Trump had been hugely critical of the existing trade deal between the two countries, slamming it as "horrible" and threatening to yank the United States out of it altogether. That raised fears of a damaging dispute that could drive a wedge between the United States and one of its closest allies in Asia. South Korea is the United States' sixth-biggest trading partner.

But after starting talks in January to renegotiate the deal, which is known as Korus, the two sides have now reached agreement on the key points, according to top officials from both countries.

Despite Trump's threats, South Korea appears to have emerged from the talks "unscathed," said Krystal Tan, an Asia economist at research firm Capital Economics.

"The concessions that Korea has agreed to will have a very small impact on its economy," she wrote in a note to clients.

Related: US and South Korea go head-to-head on trade

Under the revised deal, US automakers will get greater access to the South Korean market. Far more cars are shipped from South Korea to the United States than in the other direction, making up a big chunk of the $23 billion annual trade deficit between the two countries.

"On the whole, this is a good result," said Troy Stangarone, a senior director at the Korea Economic Institute of America, a Washington-based think tank.

Winning concessions for American automakers was crucial for the United States, he said, while South Korea will be pleased that it didn't have to give ground on opening up its agricultural industry to US imports.

Last year, the United States imported nearly $16 billion worth of South Korean passenger cars but sent only $1.5 billion worth in the other direction, according to US government figures.

Related: The world is on the brink of a trade war

South Korea's Trade Ministry said Monday that it will allow American automakers to each annually import 50,000 vehicles that meet US safety standards, double the previous quota. Beyond that threshold, cars shipped from the US will have to comply with South Korean auto-safety regulations.

US automakers have previously complained that having to comply with the South Korean rules puts them at disadvantage.

The adjustments "will make little practical difference, at least in the short term," said Tan of Capital Economics, noting that "no US automaker sold more than 11,000 vehicles in Korea last year."

Still, agreeing on changes to the trade deal "takes a potentially divisive issue off of the table" as the United States and South Korea prepare for talks with North Korea's leadership over its nuclear weapons program, Stangarone said.

US Treasury Secretary Steven Mnuchin told Fox News on Sunday that the United States had reached "a very productive understanding" with South Korea on the trade deal, but didn't provide further details.

The new agreement was announced at the same time as details on South Korea's partial exemption from Trump's controversial tariffs on steel and aluminum. The country is one of the biggest suppliers of steel to the United States.

Related: What happens when the world's two biggest economies turn on each other?

Under the arrangement, 70% of the average amount of steel that South Korea exports to the United States each year will be permanently exempt from the new 25% tariff, South Korean officials said.

Several other US allies -- including Canada, Mexico and the European Union -- have been granted temporary exclusions.

South Korean stocks responded positively to the news. The benchmark Kospi index closed up 0.8% on Monday, and shares in Posco (PKX), the country's biggest steelmaker, gained 2%.

-- CNN's Sol Han and Yoonjung Seo contributed to this report.

Updated: This story has been updated to clarify the number of cars that US automakers can send to South Korea without meeting the country's safety standards.