We humans think we’re pretty smart because we invented farming. But we didn’t.

In a rain forest in South America millions of years ago, itty-bitty ants with brains no bigger than a pinpoint had already figured it out. They started farming fungus for food — probably not too long after the Chicxulub meteor impact caused the mass extinction event that obliterated up to three-quarters of the rest of Earth’s plants and animals.

Today some 250 species of ants in tropical forests, deserts and grasslands throughout the Americas build fungi gardens in climate-controlled chambers underground. They weed them. They water them. Some even use antibiotics or chemicals to keep harmful bacteria away from their crop. Now scientists have traced the evolutionary history of how these ants became such sophisticated fungus farmers over millions of years in a study published Tuesday in the journal Proceedings of the Royal Society B.