Consider fertilizer. At one time, it was in such short supply that people scrounged for manure to nourish crops. Today, an excess of fertilizer drains from our fields; in Toledo, Ohio, this summer, fertilizer runoff from farmlands led to the growth of poisonous algae in the drinking water.

Fertilizer’s journey began in the early days of agriculture, some 10,000 years ago. With each harvest, farmers carried away life-enabling nutrients from the soil in the form of vegetables, grains, meat and milk. But the harvest stripped the soil of its fertility for the following year’s crop, resulting in puny plants, shriveled leaves and poor harvests.

Since then, humanity has wrestled with ways to mimic nature’s slow recycling machinery for keeping soil fertile. Many millennia ago, the Chinese devised a system that was as beautiful as it was repellent. When residents traveled between towns and the countryside, they carried bamboo poles on their shoulders, with buckets hanging from both ends. The buckets contained all kinds of waste—food scraps, remains from butcher shops, ash, animal manure and human waste. Euphemistically called “night soil,” this pungent mix returned nutrients to the soil.

By the time the Industrial Revolution was in full swing in the 18th century, the system had spread throughout the world. “Night men” carried away waste from big cities and sold it to farmers. As cities grew, the night men couldn’t keep up with all the muck. Flush toilets came into vogue. The cycle connecting city and countryside was broken.

A new solution to keep soil fertile arose from an unexpected source. In the early 19th century, the German explorer Alexander von Humboldt journeyed to South America to collect specimens of tree bark, herbs and rocks. One of the many samples that he carried back to Europe contained bird droppings from the islands off the Peruvian coast. The Incas had long known about guano’s virtues as a nutrient-rich fertilizer. Now European scientists were privy to the secret. A booming trade to dig up guano and ship it across the Atlantic kept soils fertile in Europe and North America throughout the 19th century. Still, the thick piles, accumulated over millennia, dwindled in a matter of decades.

Farmers were relying on another source around the same time: crushed animal bones, which yielded phosphorus needed for healthy soil. Littered bones left over from the slaughter of bison were scattered across the North American prairie. Bone pickers made a few dollars gathering the remains and loading them onto trains headed east. But like guano, the supply of bones couldn’t keep up with demand.

By the end of the 19th century, the situation looked grim. Guano and bones were depleted, and farm manure alone couldn’t nourish all the fields. Along with phosphorus, nitrogen was an essential component of fertilizer, and some scientists tried to fashion nitrogen gas extracted from the air into a fertilizer that plants could take up in their roots. Fritz Haber of Germany finally discovered a way to do this in the early 20th century, but it took enormous amounts of energy and big factories to produce sacks of fertilizer. Haber’s technology was adapted to make bombs in the first and second world wars. When demand for explosives subsided, the factories retooled to produce copious amounts of nitrogen fertilizer. The repurposed technology laid the groundwork for the 20th century’s soaring grain yields in many parts of the world.

Haber’s approach worked for nitrogen, but phosphorus was also essential. Several decades before Haber’s breakthrough, a British professor and naval captain had set out to examine some rocks a six days’ journey by bullock cart from Seville, Spain. They went on a hunch, but sure enough, veins in the granite were full of phosphorus-rich bone fragments and teeth. Miners with pick axes replaced bone pickers. A handful of other deposits turned up in countries including the U.S., China, Morocco, South Africa and Jordan.

The solution to Toledo’s recent problem is well known: using fertilizer more efficiently so that it stays on the fields rather than escaping into the water. Toledo’s troubles might nudge us another step along the winding path of problem and solution, but no solution is permanent. Eventually, the world’s phosphate deposits will be depleted.

We will then be in search of another solution. We can’t predict the future, but we can predict that solving our most pressing ecological and economic problems will be an endless, meandering process, guided by human ingenuity.

—Dr. DeFries is a professor in the department of ecology, evolution and environmental biology at Columbia University and the author of “The Big Ratchet: How Humanity Thrives in the Face of Natural Crisis,” published last month by Basic Books.