HANOI - A US aircraft carrier will port in Vietnam in March, military officials said Thursday, a first for the allies and former foes as they seek to counter Beijing's growing might in the disputed South China Sea.

The announcement came as US defence secretary Jim Mattis visited the communist nation following a stopover in Indonesia on a brief Asia tour aimed at drumming up defence cooperation.

On his two-day trip to Vietnam, where he met with his counterpart Ngo Xuan Lich and President Tran Dai Quang on Thursday, Mattis zeroed in on freedom of navigation in the resource-rich South China Sea, a thorny issue between communist neighbours Hanoi and Beijing.

China claims most of the waterway - believed to hold vast oil and gas deposits and through which $5 trillion in trade passes annually - and has built up islands and military installations in the sea.

Vietnam, Taiwan, the Philippines, Malaysia and Brunei also have claims in the waterway.

Vietnam and US defence officials have submitted requests for the aircraft carrier to visit, according to Vietnam's ministry of defence on Thursday.

Mattis thanked Vietnam for the "increasing partnership with our aircraft carrier coming into Danang in March".

Though smaller US ships have docked on Vietnamese shores, Mattis spokesman Jeff Davis confirmed it will be the first time a US aircraft carrier will port in Vietnam.

US aircraft carriers neared Vietnamese shores during the Vietnam War which ended in 1975, but this will be the first time for a carrier to port in the country, Pentagon officials said.

Mattis said earlier that freedom of navigation in the sea was crucial for fast-growing Vietnam.

"Freedom of navigation and access in the South China Sea will be critical to them economically, of course, and their security efforts," he told reporters en route to Vietnam from Indonesia on Wednesday.

Military ties between the former foes have improved in recent years. In 2016 former US President Barack Obama, on a visit to the one-party state, lifted an arms embargo in place since the end of the Vietnam War.

Vietnam's Defence Minister Ngo Xuan Lich visited Mattis in August 2017, part of Hanoi's campaign to keep Washington close under US President Donald Trump.

Mattis, who is in Vietnam for the first time, heads back to the US on Friday, capping a five-day trip to the region that included a memorable military performance in Indonesia involving snake sacrifice and flaming bricks.