China and Vietnam have resolved a border dispute 30 years after a war which left tens of thousands dead.
The two countries announced they had completed the demarcation just hours before a midnight deadline.
Government teams from both sides had worked for years planting stones to mark the line of the frontier which stretches 1,350 km (840 miles).
China and Vietnam both hailed the agreement, but neither mentioned any progress on a separate maritime row.
"The completion of the land border demarcation between China and Vietnam will promote the development of the China-Vietnam strategic partnership," said Chinese Deputy Foreign Minister Wu Dawei.
Mr Wu said the agreement would also "benefit peace, stability and development" in the region.
The BBC's Nga Pham in Hanoi said the last-minute agreement had caught observers by surprise.
Many had believed that there were differences between the two sides that could not be quickly resolved.
However, it was not clear whether the two parties had signed any official protocol on the completion of land border demarcation and no map of the newly-defined border was released, says our correspondent.
The two neighbours, which normalised relations in 1991, have had an uneasy relationship.
China supported the Vietnamese Communists during the Vietnam War, but Vietnam is wary of its huge northern neighbour and the countries have had several confrontations in the past few decades.
These include disputes over the Spratly Islands, a strategic string of rocky outcrops in the middle of the South China Sea, to which both countries, as well as several others, have laid claim.
Analysts say border and territory controls have always been highly sensitive issues in Vietnam.
Last year, public grievances over China's claims to the Spratlys led to mass anti-Beijing protests in the Vietnamese capital Hanoi and in Ho Chi Minh City.