Dairy farmers in California, the nation’s top milk producer, face pressure from rising costs, increasingly complex environmental regulations and a quest for water—challenges all magnified by a historic drought. For some, the challenges are existential.

In the north coast, home to the state’s small, organic dairy farms, shrunken reservoirs and shriveled pastures pushed some farmers to the brink earlier this year. In the San Joaquin Valley—a vast agricultural region in the center of the state where 90% of California’s milk is produced—farmers are paying more for cow feed and water, driving up the cost of producing a gallon of milk.

California’s milk production, combined with dairy processing, brings more than $20 billion annually to the state economy. Dairy is the top farm industry by revenue in California, the nation’s biggest agricultural state.

Growing challenges have spurred a shift in the past decade, prompting some California dairy farmers to move, shut down, or turn to growing crops. Recurring droughts are now intensifying their struggles, boosting milk sheds further east and threatening the state’s dairy-capital status, according to farmers, agricultural economists and industry groups.

California is expecting a dry winter, which would further strain existing shortages. The state said Wednesday that for the first time, it might not have enough reserves to distribute water to local districts, which handle flows to homes, businesses and farms.

Mike Monteiro, 58, a third-generation dairy farmer, spent the spring waiting for rain. Little came, signaling a second season of drought and dashing hopes that water would flow like it usually does, from reservoirs to his fields and barns in central California.

He turned to water below ground, switching on the pumps in his wells. Within months, they were delivering just half their normal volume. One well began pumping sand.

By summer, Mr. Monteiro called it quits on two of his three dairies, located in Tulare County, America’s largest dairy county. “If we stay dry, these older facilities will have to get shut down in the next three years,” he said.

Similar decisions are playing out across California as back-to-back droughts in the state force farmers to make choices about where—or whether—they will be able to continue raising the crops or livestock that make up a pillar of the region’s economy.

Dairy farms are huge consumers of water. A lactating cow drinks as much as 50 gallons of water a day, and much more is used to grow crops to feed herds.

In the San Joaquin Valley, dairy farmers short on water this year have fallowed land devoted to feed crops such as corn and alfalfa, or pulled back on irrigation, hurting yields.

To fill the gap, they and others have had to purchase feed from surrounding counties and states, in a year when costs have soared. Prices for corn and soybeans from the Midwest are sharply higher due to tight supplies. Western drought compounded the problem, denting harvests and pushing up prices for feed products from alfalfa to almond hulls.