Chocolate has been a delicacy for much longer than previously thought.
Botanical evidence shows the plant from which chocolate is made was first grown for food more than 5,000 years ago in the Amazon rainforest.
Chemical residues found on ancient pottery suggest cocoa was used as a food, drink or medicine by indigenous people living in what is now Ecuador.
Until now it was thought that chocolate originated much later and in Central rather than South America.
"The plant was first used at least 1,500 years earlier than we had previous evidence for," said Prof Michael Blake of the department of Anthropology at the University of British Columbia in Vancouver, a co-researcher on the study.
Researchers analysed pottery vessels from the Santa Ana (La Florida) archaeological site in the highlands of Ecuador, which was occupied between 5,300 and 2,100 years ago.
A number of crops have been documented there, including corn, sweet potatoes and the cacao tree Theobroma cacao.
Traces of chemicals and DNA from the plant were found on pottery, suggesting the ground seeds of the cocoa pod were being mixed into a concoction and drunk.
The study corroborates DNA data pointing to the tree's origin in the upper Amazon region of northwest South America, which is where the domestic crop also originated.
"It's another gift of the people of Amazonia to the world," said Prof Blake. "It highlights the importance of protecting this habitat."
It is thought that seedlings or seeds of the cocoa tree were carried north into Mexico and Central America, perhaps along sea routes.
Cocoa beans became precious commodities, used as food and drink by the wealthy, or traded for other foods.
Spanish explorers in the 1520s took the cocoa beans home and spread the delicacy throughout Europe.