The United States and Mexico on Tuesday signed a pact for new rules on sharing water from the Colorado River, capping a five-year effort on how to spread the pain of drought and reap the benefits of wet years.

The far-reaching agreement gives Mexico badly needed water storage capacity in Lake Mead, which stretches across Nevada and Arizona.

Mexico will forfeit some of its share of the river during shortages, bringing itself in line with western U.S. states that already have agreed how much they will surrender when waters recede. Mexico also will capture some surpluses when waters rise.

Also under the plan, water agencies in California, Arizona and Nevada will buy water from Mexico, which will use some of the money to upgrade its canals and other infrastructure.

The agreement, coming in the final days of the administration of Mexican President Felipe Calderon, is a major amendment to a 1944 treaty considered sacred by many south of the border. The treaty grants Mexico 1.5 million acre-feet of river water each year – enough to supply about 3 million homes – making it the lifeblood of Tijuana and other cities in northwest Mexico.

The pact represents a major departure from years of hard feelings in Mexico about how the U.S. manages the 1,450-mile river, which runs from the Rocky Mountains to Mexico. In 2001, U.S. states established rules on how to divide surpluses but set aside nothing for Mexico. Several years later, the U.S. government lined a border canal in California with concrete to prevent water from seeping through the dirt into Mexican farms.

“We have chosen collaboration over conflict, we have chosen cooperation and consensus over discord,” said U.S. Interior Secretary Ken Salazar, who called the new pact the most important international accord on the Colorado River since the 1944 treaty.