Landlocked Bolivia is getting a tiny sliver of the Pacific - a dock, a free-trade zone and the right to run some naval vessels, although the agreement signed with Peru falls far short of what Bolivians have dreamed of for 126 years - a coastline of their own.
President Alan Garcia announced the pact during a ceremony at the southern Peruvian port of Ilo.
It is part of a long-standing crusade by both Peru and Bolivia to prod neighbouring Chile into giving back some of the territory it seized in the 19th century War of the Pacific.
"It is unjust that Bolivia has no sovereign outlet to the ocean," Mr Garcia said, with Bolivian President Evo Morales at his side. "This is also a Bolivian sea."
Mr Morales said the agreement would give Bolivia a gateway to export its products and he vowed that "Bolivia, sooner or later, will return to the sea".
Peru first granted Bolivia use of a three-mile strip of beach in 1992, but the declaration was largely symbolic: Bolivia never managed to use it due to lack of transportation links and infrastructure.
Widely touted plans for a Bolivian natural gas line to Ilo and a Brazil-Bolivia-Ilo highway evaporated.
Under the new 99-year deal, Peru is granting Bolivia dock facilities, a free-trade zone and space for economic activities. It can also build a Pacific Coast annex for the Bolivian navy school, which until now largely has been limited to rivers and Lake Titicaca.
Peruvian Foreign Minister Jose Antonio Garcia Belaunde told Radioprogramas radio that the agreement lets Bolivia own property in the zone - dropping a prohibition in the 1992 pact.
Chile's victory in the 1879-1884 war gave it mineral-rich territories once held by Peru and Bolivia, and the three neighbours have since engaged in constant territorial feuding.