The UN chief was in Santa Cruz, Bolivia for a meeting this weekend of the G77 group of countries to discuss measures for reducing poverty.
Coca is used to make cocaine but host Morales, a former coca farmer, has long defended its legal use as an "ancestral rite" for tea, sweets and medicines, going so far as to pull coca leaves out of a small plastic bag during a UN anti-drug meeting in Vienna in 2012 and chew on a wad of them. People in the Andean region also traditionally chew on coca leaf as a source of energy or as an antidote to altitude sickness.
"The Bolivian people will never forget your visit," Morales told Ban on Friday in front of hundreds gathered for the presentation of the cake and a traditional Bolivian jacket.
Ban was effusive in his thanks but stopped short of publicly taking a bite of the "torta de coca" or of endorsing Morales' position on the controversial leaf.
"The Bolivian people have a big, broad heart ... and great wisdom," Ban said. "You have lived for thousands of years in harmony with nature."