The first thing Roger Muggli learned about irrigation was that water runs downhill.  His grandfather managed an irrigation district near Miles City, Mont., and together they tended the ditch. From the fields they would trace the water's passage to an oxbow on the Tongue River. Now, Muggli, 62, works the same job alone, patching pipes, scouring the canal and cutting debris from the banks.  When the soil thaws and alfalfa sprouts, he opens the headgates, and water rushes into the main ditch. There, it meets smaller ditches and seeps into the furrows like blood across a weathered palm.

Muggli has seen dry years, but never like 2004 and 2006, when his irrigation district had only half its water right fulfilled. A normal season yields 100 barley bushels per acre, but he threshed no more than 45. Where the Tongue River crosses into the state from Wyoming, a reservoir that often overflowed never even filled. "It was a logistical nightmare," says Muggli. "People don't like you turning off their water."

Meanwhile, in Wyoming, water commissioners fielded calls from senior water-rights owners who weren't seeing their share. In response, they cranked headgates closed, shutting off newer rights first in accordance with basic water law. In one drainage in 2006, the only user left operating had rights dating to 1890. But along the main stem of the Tongue, a few junior water rights holders operated all season. There was nobody downstream to complain, but Montanans.

"First in time, first in right" guides how water is divvied up within states but doesn't always apply across borders. Wyoming and Montana instead rely on the 1950 Yellowstone River Compact, which governs how the states share four Yellowstone tributaries -- the Powder, Tongue, Bighorn and Clarks Fork -- in times of scarcity. It guarantees both states continued access to any rights issued before 1950. To satisfy later rights, the states are promised fractions of each river's remaining flow.

The Compact's drafters suspected that the Yellowstone's tributaries were already fully allocated in 1950. They hoped the agreement would satisfy Montana's older water rights in dry years, even if Wyoming kept issuing new ones. But post-1950 rights were not Montana's only trouble. Over time, water use changed: Irrigators swapped ditches for center-pivot sprinklers, and energy companies drilled the first coalbed methane wells, pumping vast amounts of water from deep aquifers.

For years, water was plentiful, so Montana didn't worry. Only when the state's senior water users received less than ever before did they begin to wonder where their water had gone. In both 2004 and 2006, Montana asked Wyoming to release water from storage to satisfy the pre-1950 rights it thought were guaranteed. Wyoming refused. In 2007, Montana sued Wyoming for violating the Yellowstone River Compact. The case landed in the Supreme Court this January.

Montana attorneys can't say for sure where their state's water went those years. But they suggested four possibilities that made Wyoming liable: groundwater extraction; excessive water storage; new uses like coalbed methane; and advances in irrigation technology that allowed farmers to consume more of their water right than before. (Wyoming's explanation was simpler: drought.) The special master -- a water-law expert appointed to review the case and advise the Supreme Court -- sided with Montana on the first three claims, but with Wyoming on the fourth. Montana objected on that last count, so the question was put to the High Court itself, which on May 2 decided in Wyoming's favor. The decision allows Wyoming farmers to switch to advanced irrigation technology even if it means consuming water that otherwise would flow back to the river for another user.

Irrigation efficiency has its merits, but it's created unexpected downstream shortfalls that Montana farmers may now be forced to live with. Unlike many similar agreements in the West, the Yellowstone Compact never quantified the minimum amount of water Wyoming must deliver to Montana each year.  And it was written at a time when gravity, not pumps, governed water use. "People don't always anticipate what's going to happen over time," says Barbara Cosens, professor of law at the University of Idaho. "The older compacts did not account for groundwater development. Nor did they anticipate that irrigation efficiency works very different in practice than in theory."