Thai Prime Minister Anutin Charnvirakul and his Cambodian counterpart Hun Manet signed the agreement at a ceasefire ceremony in front of a sign that read "Delivering Peace", building on a truce signed three months ago.
"This declaration, if fully implemented, will provide the building blocks for a lasting peace, but more importantly, it will begin the process of mending our ties," Hun Manet said.
"Our border communities have been divided by conflict, and innocent civilians have suffered immense losses."
Trump helped broker an end to the five-day conflict in July by calling the then-leaders of the two countries and urging them to end hostilities or risk their respective trade talks with Washington being put on hold.
"The United States will have a robust commerce and co-operation, transactions, lots of them, with both nations, as long as they live in peace," Trump said.
Both sides blame each other for escalating an exchange of rockets and heavy artillery that killed at least 48 people and temporarily displaced an estimated 300,000 people in their worst fighting in recent history.
Anutin almost missed the signing after the death of the kingdom's Queen Mother Sirikit on Friday, but later decided to fly in for the ceremony.
He said both sides would remove "heavy weapons from the border areas to ensure the safety of our people" and that Thailand would release 18 detained Cambodian soldiers.
On arriving in Malaysia, Trump was greeted by Prime Minister Anwar Ibrahim and a troupe of ceremonial dancers at Kuala Lumpur International Airport.
Anti-Trump demonstrations were also being held in Kuala Lumpur, with some protesters holding signs saying the president was not welcome in Malaysia.
As Trump mingled with other leaders, US and Chinese negotiators met on the sidelines to avert further escalations in a trade war between the world's two largest economies.
Asked by a reporter if rare earths were discussed at the talks, which started on Saturday, top US trade negotiator Jamieson Greer said a broad range of topics was canvassed, including extending the truce on trade measures.
"I think that we're getting to a spot where the leaders will have a very productive meeting," Greer said.
China's stranglehold over global supplies of rare earths is at the heart of the negotiations, and Washington has sought to diversify supply chains.
Within hours of landing in Malaysia, Trump had finalised trade agreements with four countries, including deals involving critical minerals with Thailand and Malaysia, amid competing efforts from Beijing in the rapidly growing sector.
Malaysia on Sunday agreed to refrain from banning or imposing quotas on exports to the US of critical minerals or rare earth elements, the countries said in a statement.
They did not specify whether Malaysia's pledge applied to raw or processed rare earths.
Trump also announced a wider trade deal with Cambodia while the White House said an agreement had been reached with Vietnam to allow "both countries' exporters unprecedented access to each other's markets".
The US would maintain a tariff rate of 19 per cent on most exports from Malaysia, Thailand and Cambodia, while a 20 per cent rate on Vietnam would also be retained, the White House said.
Trump also held a brief meeting with Brazilian President Luiz Inacio Lula da Silva, who is among several world leaders attending the summit.
Lula will aim to lower 50 per cent tariffs imposed by Washington on Brazilian goods.
A meeting with Canadian Prime Minister Mark Carney was not on the cards after talks between the neighbours came to an abrupt end.
Trump said on Saturday he was increasing tariffs on Canada by an additional 10 per cent "above what they're paying now".