Vietnam's President Tran Dai Quang and U.S. President Donald Trump address a joint news conference at the Presidential Palace in Hanoi Thomson Reuters By Steve Holland and Mai Nguyen

HANOI (Reuters) - U.S. President Donald Trump said on Sunday he was prepared to mediate between claimants to the South China Sea, where five countries contest China's sweeping claims to the busy waterway.

Trump was speaking in Vietnam, which has become the most vocal opponent of China's claims and its construction and militarization of artificial islands in the sea. About $3-trillion in goods passes through the sea each year.

"If I can help mediate or arbitrate, please let me know," Trump said in comments at a meeting in Hanoi with Vietnam's president, Tran Dai Quang.

Trump acknowledged that China's position on the South China Sea was a problem.

"I'm a very good mediator and arbitrator," he said.

President Quang said Vietnam believed in handling disputes on the South China Sea through peaceful negotiations and on the basis of international laws - which Vietnam says nullify China's claims.

Vietnam has reclaimed land around reefs and islets, but on nowhere near the same scale as China. Brunei, Malaysia, the Philippines and Taiwan also have claims in the sea.

Since Philippine President Rodrigo Duterte has grown closer to China, Vietnam has emerged as China's main challenger in the region. In July, China pressured Vietnam to stop oil drilling in a disputed area, taking relations to a low.

Relations have since improved and Chinese President Xi Jinping is visiting Hanoi later on Sunday.

The South China Sea was discussed in Beijing on an earlier leg of Trump's 12-day Asian tour and U.S. Secretary of State Rex Tillerson said the United States and China had a frank exchange of views.

The United States has angered China with freedom of navigation patrols close to Chinese-controlled islands.

CODE OF CONDUCT

In August, foreign ministers of Southeast Asia and China adopted a negotiating framework for a code of conduct in the South China Sea, a move they hailed as progress but one seen by critics as a tactic to buy China time to consolidate its power.

The framework seeks to advance a 2002 Declaration of Conduct (DOC) of Parties in the South China Sea, which has mostly been ignored by claimant states, particularly China, which has built seven man-made islands in disputed waters, three of them equipped with runways, surface-to-air missiles and radars.

All parties say the framework is only an outline for how the code will be established and critics raise doubts about how effective the pact will be.

The framework will be endorsed by China and members of the Association of Southeast Asian Nations (ASEAN) at a summit in Manila on Monday, a diplomat from one of the regional bloc's countries said.

The next step is for ASEAN and China to start formal consultations and negotiations for the actual Code of Conduct, and the earliest that talks on this can start is February 2018, the diplomat said.

From Vietnam, Trump flies to the Philippines for a meeting with ASEAN leaders before he heads back to Washington.

Relations between Vietnam and the United States have blossomed in the decades since their war ended in 1975. A recent survey put the favorability of the United States at 84 percent among Vietnamese.

But Vietnam's trade surplus remains an irritant for the Trump administration. At $32 billion last year, it was the sixth largest with the United States, though less than a tenth the size of China's.

"We want to get that straightened out very quickly," Trump said at a meeting with Prime Minister Nguyen Xuan Phuc.

(Writing by Matthew Tostevin; Editing by Clarence Fernandez)