Centuries before spirulina was deemed a "superfood", the vibrantly coloured cyanobacteria (or blue-green algae) was a pre-Hispanic dietary staple.

If you've spent any time dining in Mexico City recently, you may have noticed spirulina cropping up on menus in everything from the usual smoothies to more traditional dishes such as tortillas and tlayudas (a crisp tortilla base with refried beans and other toppings). But don't assume this is some symbol of encroaching hipster health food globalisation: in fact, centuries before it was deemed a "superfood", the vibrantly coloured cyanobacteria (or blue-green algae) – which grows primarily in warm alkaline lakes, ponds and rivers in the tropics and subtropics – was a pre-Hispanic dietary staple.

Even without modern science, the Mexica could recognise the nutrient density

The Mexica – or Aztecs, as they were later known – harvested the protein-rich substance from the surface of Lake Texcoco, an expansive body of water in central Mexico that was later largely drained by the Spanish to make way for the construction of Mexico City. Here, the waters exhibited the perfect balance of salinity and alkalinity for spirulina to flourish. The Mexica called the foodstuff tecuitlatl, a Nahuatl word that roughly translates to "rock excrement", though they held it in decidedly higher esteem than its name suggests.

"Oral traditions say that the Mexica couriers and runners in ancient Tenochtitlan would eat dried spirulina cakes with corn, tortillas, beans, chillies or mole as fuel for long-distance travel," said Denise Vallejo, an indigenous first-generation Xicana chef who runs the vegan Los Angeles pop-up Alchemy Organica.

Even without modern science, the Mexica could recognise the nutrient density that has made spirulina such a favourite today. It boasts about 60-70% protein by weight and has essential amino acids and many vitamins and minerals, especially iron, manganese and B vitamins, according to the Encyclopedia of Dietary Supplements. It's so healthy and relatively easy to grow, in fact, that experts think it could be a potential food source for future Mars colonies.

Of course, to the arriving Spanish conquistadors in the 16th Century, it mostly just looked odd. Bernal Díaz del Castillo wrote in his 1568 memoir about "a species of bread made of a kind of mud or slime collected from the surface of the lake, and eaten in that form, and has a similar taste to our cheese." And Franciscan friar Bernardino de Sahagún included illustrations of spirulina harvesting in his 16th-Century ethnographic study, the Florentine Codex.

"After the Spanish invasion, most of its consumption declined with the draining of the lakes in the Valley of Mexico," Vallejo said. "And many of the Spanish didn't enjoy its 'cheesy' or 'slimy' properties. Knowledge of its consumption was lost for a long time."

The Western world rediscovered the nutritious ingredient in the 1940s, when a French phycologist (a scientist who studies algae) noticed the Kanembu people along Africa's Lake Chad harvesting spirulina and turning it into sun-dried cakes called dihé. But it didn't make its grand return to Mexico until a happy accident in the 1960s, when the owners of Sosa Texcoco – which produced sodium carbonate and calcium chloride in a large snail-shaped pond on the remnants of Lake Texcoco – noticed a green substance mucking up the works. They reached out to French researchers, who concluded that it was the same organism that had been nourishing the Kanembu for generations. Rather than try to eradicate the cyanobacteria, Sosa Texcoco recognized its value, encouraged its growth and opened the world's first commercial spirulina company, Spirulina Mexicana.

While Spirulina Mexicana has since closed, a micro-farm on the outskirts of San Miguel de Allende called Spirulina Viva is continuing the ancient tradition. Since 2010, American expat Katie Kohlstedt and her San Luis Potosí-born husband, Francisco Portillo, have grown fresh spirulina that probably tastes remarkably similar to what the Mexica harvested centuries ago. "We're really proud to grow it here," she said. "We didn't have to invent something new or bring something from somewhere else."

You may also be interested in:
Mexico's ancient caviar
Where there's no queso in quesadilla
Mexico City's walking fish

While many people may be familiar with spirulina in its dehydrated powdered form, Spirulina Viva sells the green stuff raw and frozen, which imparts a much more delicate flavour. "Fresh spirulina should be creamy like a spreadable cheese," Kohlstedt said. "If you closed your eyes, you might think you were eating a cross between an avocado and spinach." She noted that if you think of spirulina as fishy or an acquired taste, chances are you've been buying a lesser-quality product – or even one that uses ground fish bones to provide the phosphorus the spirulina needs to grow.

Kohlstedt and Portillo lead spirulina-growing workshops and have welcomed future farmers from as far away as Australia and Argentina. "It's gardening combined with chemistry," Kohlstedt said of the process. But for many consumers, the finished product still remains a bit of a mystery. "If I read one more article that said spirulina is grown in the ocean or [that shows] a picture of seaweed, I'm just going to scream," she said, with a laugh. "My other two least favourite words are 'pond scum'. I think that's really offensive actually!"

If I read one more article that said spirulina is grown in the ocean or [that shows] a picture of seaweed, I'm just going to scream

Kohlstedt recommends eating spirulina as simply as possible, stirred into warm miso soup or bone broth, blended into a smoothie, spread on bread or mixed into guacamole with extra lime juice, because vitamin C has been shown to help iron absorption. "You're going to feel like you just ate Popeye's lunch," she said.

In Mexico City, chefs are getting even more creative with the ingredient. You might find spirulina dusting a tlayuda topped with avocado and escamoles (ant larvae) at Balcón del Zócalo; brightening a superfood tortilla at Cintli Tortilleria; adding a verdant punch to the smoothie bowls and cheesecakes at Vegamo; and even spiking cocktails at the pre-Hispanic-inspired Xaman Bar.

There, head bartender Kenneth Rodrigez has incorporated spirulina into a number of drinks, including a gin-based cocktail with Mexican lime and asparagus liqueur. "I use it when somebody doesn't like egg whites or [in drinks for] vegan people, because spirulina has protein and we can get interesting textures," Rodrigez said, "not to mention the incredible colour and the nutritional components that it provides." 

He describes the taste notes as "green, herbal and clorofila (chlorophyll)," and said that "it can be used to enhance other flavours, because it has lots of minerals, like an alternative for salt." 

Across the border in Mexican American communities, using spirulina has meant establishing a direct connection with a pre-Hispanic past. At San Antonio's inventive Mexican restaurant Mixtli, for instance, chefs Rico Torres and Diego Galicia featured spirulina on a special menu inspired by the Spanish conquest, and they participated in a collaborative Día de los Muertos dinner at New York's JamesBeard House, where one of the hors d'oeuvres was a smoked spirulina yogurt with trout roe and radishes.

At Alchemy Organica, Vallejo incorporates spirulina powder into a pineapple agua fresca (a Mexican drink made with water, sugar and pureed fruits, seeds, flowers or grains for flavour) with lime and chia seeds. And she has even used it as "a natural food colouring and nutritional boost, along with cactus and spinach powders" to make vibrant green masa (dough made with corn that has been nixtamalized, or treated with an alkaline solution), which she turns into colourful tortillas and tamales. "I also use it as a flavour enhancer for some of my seafood-inspired dishes, as it imparts a flavour much like seaweed," she explained. 

And when one of her cooks began selling fresh spirulina at a farmer's market, Vallejo took to simply scooping spoonfuls into her drinks. "It gives you energy like you'd expect from a cup of coffee!" she said.

In a sense, these chefs are tapping into something much deeper than simply taste or nutrition. Vallejo, who studies curanderismo (folk medicine), said that spirulina is often viewed as a detoxifier to prepare for rituals, spells and "visionary plant ceremonies". And Kohlstedt has similarly heard about the ingredient's mystical connections, which draw on the similarities between spirulina's helical shape and our own building blocks as humans: "Someone told me that the reason it's called 'spirulina' has to do with its spiral form, but that it also has to do with our DNA and how there is something really basic and spiritual about how we relate to plants [and cyanobacteria]."

"So many of the 'superfoods' enjoyed today have a rich history in Mesoamerica: chia, amaranth, cacao, avocado, cactus," Vallejo noted. "I think the current decolonising movement in Xicanx, Central American and other Spanish-speaking communities is helping us to rediscover and remember our ancestral foodways. We get to take back our foods and our plant wisdom. The more we eat them, the more we awaken that DNA and that history."

Ancient Eats is a BBC Travel series that puts trendy foods back into their ‘authentic’ context, exploring the cultures and traditions where they were born.

Join more than three million BBC Travel fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "The Essential List". A handpicked selection of stories from BBC Future, Culture, Worklife and Travel, delivered to your inbox every Friday.