Armed Vietnamese soldiers watched as a U.S. aircraft carrier approached their country's coastline Monday for the first time in more than four decades. But the vessel was on a mission of diplomacy, not war.

The port call involving nearly 6,000 sailors marks the largest U.S. presence in Vietnam since the 1975 U.S. withdrawal following years of combat — a stark picture of how China's solidifying grasp of the strategic South China Sea has prompted Vietnam to rethink its defense alliances in the region.

"This is a historic day and we are honored to receive such a warm welcome here," said Rear Adm. John Fuller, the strike group commander.

The four-day port call is part of an ongoing U.S. effort to court Vietnam. Defense Secretary Jim Mattis visited the country in January to tout strengthening ties with the country on the heels of a new strategy to refocus defense efforts on big-power militaries. He called on the Pentagon to keep pace with a resurgent Russia and China by building relationships in key regions such as Southeast Asia.

And Vietnam, increasingly emboldened to challenge Chinese territorial claims in the resource-rich sea, is a critical component of the strategy to further develop military relations, Mattis said on his visit. "America wants a stronger relationship with a stronger Vietnam," he said.

Military relationships between the nations are still taking shape. Last year, the United States sold Vietnam a Coast Guard cutter, which officials said became the largest ship in its fleet.

China has claimed nearly all the South China Sea. It has chiseled military outposts and runways from rock and claimed dominion over islands and waterways where $3 trillion in trade flow every year, triggering condemnation from an international tribunal ignored by Beijing. Vietnam's claims of fishing and navigational waters and a smattering of islets off its coast considerably overlap with China's disputed claims, leading to occasionally tense standoffs.

But Vietnam navigates a complicated relationship defined by geography and its history with China. Vietnamese diplomats have been adept at pushing back on Chinese expansion while keeping military and economic relations mostly healthy, said Zack Cooper, an analyst at the Washington-based Center for Strategic and International Studies.

Vietnam stands mostly alone among the Philippines, Malaysia, Brunei and Taiwan in challenging China's claims. After Philippine President Rodrigo Duterte acquiesced to Chinese pressure to back down on claims in the area, a spokesman for the longtime U.S. ally called the issue "America's problem."

The United States has no territorial claims in the sea but conducts what the military calls "routine and regular" patrols through its waters.