There's a system of swampy red mangroves, deep in the rainforests of the Yucatan peninsula, that's a long, long way from home.

The nearest seashore lies 170 kilometers away (105 miles), and yet these salt-loving shrubs didn't just get up and walk away from the coastline for a fresh drink on the banks of the San Pedro river.

Combined genetic, geologic, and botanical research has now confirmed what many locals and scientists have suspected: this was once an ancient saltwater mangrove ecosystem left stranded during the last ice age, when the oceans receded.

What we see today is thus the freshwater relic of a coastal lagoon ecosystem some 125,000 years old.

"This discovery is extraordinary," says biologist Felipe Zapata from the University of California Los Angeles.

"Not only are the red mangroves here with their origins printed in their DNA, but the whole coastal lagoon ecosystem of the last interglacial has found refuge here."

Red mangroves (Rhizophora mangle) usually grow in brackish or salty tidal waters of the tropics, but in rare instances they are sometimes found in freshwater too.

When calcium deposits are rich enough, the mangroves can establish themselves without any need for nutrients from the sea.

Several other studies along the Mexican Caribbean coast have found possible 'fossil lagoons' that have also been separated from the sea, although they are not nearly as far away as the one found on the limestone banks of the San Pedro.

Analyzing the genomes of 79 trees at 11 sites around the Yucatan, researchers found river populations of red mangroves were distinct from coastline populations of red mangroves.

The freshwater trees were most closely related to a mangrove found at Términos Lagoon on the Gulf of Mexico side of the Yucatan, which suggests these two mangroves are sisters and share a common ancestor derived from the northside of the peninsula.

Other inland lagoons in Mexico, on the other hand, appear to be connected to Caribbean mangroves, which suggests there are two distinct lineages of R. mangle: one from north and one from south.

"The population genetic analysis confirms that San Pedro River mangroves are a relict of a coastal ecosystem that colonized the river's tufa lakes, possibly during the Last Interglacial, and stayed behind along the riverbanks after the oceans receded during the Wisconsin glaciation," the authors surmise.

Running models on sea level data for the southern Gulf of Mexico, researchers identified a low coastal plain that could easily turn into a bathtub if sea level rose even a little bit.

Before the last glaciation event, all the polar ice caps had melted and sea levels were roughly 6 to 9 meters (20 to 30 feet) higher than what we see today.

According to the models, that's enough to flood the Tabasco lowlands of Mexico and submerge the tropical rainforests that border the San Pedro. The 'tub' was filled with saltwater within centuries, researchers say.

That means in only a few generations, red mangroves were able to establish themselves along the shifting coastlines.

Other smaller species of vegetation were also able to colonize these new environments quite rapidly. Nearly a hundred are still there to this day.

The unique ecosystem is a direct line back to Earth's last warming event, and it could tell us important information about where we are headed now.

Sea levels aren't going to rise 9 meters with human-caused climate change just yet, but by 2300, some models predict the world's seas could rise five meters above what they are today.

How ecosystems will cope with that change remains to be seen, but perhaps resilient natural habitats like the red mangrove can give us hints of what is to come.

"The most amazing part of this study is that we were able to examine a mangrove ecosystem that has been trapped in time for more than 100,000 years," says first author, marine ecologist Octavio Aburto-Oropeza from the University of California San Diego.

"There is certainly more to discover about how the many species in this ecosystem adapted throughout different environmental conditions over the past 100,000 years. Studying these past adaptations will be very important for us to better understand future conditions in a changing climate."

But to understand the San Pedro mangrove system, it needs to exist. And right now, it's under severe threat. In the 1970s, the rainforests surrounding this river were heavily deforested. The mangroves only survived because they were too tough to reach.

The authors of the study argue we need to protect and conserve these ancient ecosystems to understand where we've been and where we're going.

The study was published in PNAS.