Five hundred scientists meeting in Bonn last month warned that 9 billion people would face the consequences of severe water shortages within a generation or two, but did not point the finger at industries devastating fresh water supplies.

Meanwhile, a battle against a metal mining industry that has ravaged freshwater supplies in El Salvador shows just how difficult it is for a developing country to build economic alternatives for a water-secure future.

Two mining companies are dragging El Salvador through a costly legal challenge at an international trade tribunal for attempting to protect limited water supplies by refusing permits for their operations.

With 90% of its surface water heavily contaminated and a quarter of its rural population lacking access to safe drinking water, El Salvador is embroiled in a clean water crisis. More than two-thirds of the population rely on the Lempa river basin for drinking water – the same number that would be threatened by water-intensive and water-contaminating metal mining projects were El Salvador to reopen its doors to the industry.

In 2008, after strong public pressure to protect water from mining, Antonio Saca, El Salvador's president at the time, declared he would not issue any new mining permits. There are no active metal-mining operations in the mineral-rich country, which a majority of Salvadorans would like to become the first in the world to prohibit metal mining permanently. A bill to ban the industry has the support of more than 62% of the population and was initially backed by the ruling FMLN party.

The canton of San Sebastián stands as an emblem of a past where mining companies were given free rein to mine, resulting in the contamination of fresh water. Milwaukee-based Commerce Group ran a gold mining operation in the area until 1999. The community has nothing to show for decades of gold extraction but the famous bright orange waters of the San Sebastián river, a classic sign of acid mine drainage from large-scale gold mining. The Salvadoran environment and natural resources ministry tested the water in 2012 and found nine times the accepted levels of cyanide and 1,000 times the accepted levels of iron.

Without a clean water supply, local subsistence activities have been devastated. Residents are forced to buy bottled water, but continue to use the highly toxic water from the river for feeding livestock, bathing, and doing dishes.

Experiences like that of San Sebastián have galvanised people in other parts of the country. In the northern department of Cabañas, neighbourhood associations, church groups and environmental groups have organised a strong campaign against a cyanide leach gold mine proposed by Vancouver-based Pacific Rim. With the help of a Spanish NGO, Asociación Catalana de Ingeniería Sin Fronteras, a community organisation in Cabañas has armed itself with an extensive baseline study of its water and started implementing measures to improve water quality. Local groups have also led the national campaign for a permanent ban on metal mining, and were initially backed by the broad-based civil society coalition called La Mesa Nacional Frente a la la Minería Metálica.

As Manuel Perez-Rocha of the Washington-based Institute for Policy Studies observed during a recent fact-finding mission to El Salvador involving 45 international delegates from 12 different countries: "The contrast between the communities exposes the myths of mega mining. Rather than generate wealth for the communities, decades of mining have left the people impoverished in San Sebastián, whereas the communities of Cabañas are well organised and are exploring their own vision for development."

Salvadorans are simultaneously trying to pave the way for a clean water future through an ambitious new water bill currently being debated at the national assembly. The proposed bill would engage 25 different government agencies in a series of measures ranging from universal access to water and sanitation to protecting source water and prohibiting activities that would destroy watersheds. It would establish a hierarchy of water use that would prioritise clean water for human consumption and food production.

Meanwhile, both Commerce Group and Pacific Rim are using a World Bank trade tribunal to circumvent community consent and state regulation. They are suing the Salvadoran government for more than $400m through the International Centre for the Settlement of Investment Dispute (ICSID), whose mandate is to protect investment rights.

The legal challenge appears to have have had a chilling effect politically. Negotiations around policies that would be unfavourable to the mining industry have become gridlocked, and civil society actors fear the ruling party may make concessions to the pro-mining opposition. If ICSID forces El Salvador to pay the companies, it would make goals such as universal access to water and sanitation impossible.

As scientists and world leaders deliberate on how to fix the global water crisis, there should be greater international support for communities and countries attempting to forge new paths away from water-destructive economies. If El Salvador overcomes the odds and becomes the first country in the world to ban metal mining, it could serve as a model for a world grappling with the threat of an imminent water crisis.

With a recent poll showing a close race between the ruling party and the pro-mining opposition for the 2014 presidential election, the window for change may be closing.