Four years ago, the pipes under Missoula, Montana, were leaking nearly 8,000 gallons of water a minute and, by the city’s tally, needed nearly $100 million in repairs. But Missoula couldn't fix it: A private company owned the water system.

Missoula took the owners to court, using eminent domain laws to bring its fully privatized water system back under public control. Around the same time, 1,170 miles south, Rialto, California, was looking to private companies to help solve its own water infrastructure problems. It signed a 30-year concession agreement with investors, hoping to infuse its aging water system and local economy with outside cash — and created almost exactly the sort of public-private partnership President Donald Trump has encouraged cities and states to pursue under his new infrastructure plan.

While public-private partnerships have been used with varying degrees of success for transportation projects like toll roads and airports, the infrastructure proposal Trump released on Monday offers incentives for local officials to seek more outside money for a broader range of projects. But what happens when private investors hold the keys to critical infrastructure systems, like water? Do consumers reap the benefits of private sector expertise and efficiency, or suffer as investors profit?

"It can be a good deal," Rialto Mayor Pro Tem Ed Scott told NBC News. But Missoula Mayor John Engen says he’d advise municipalities to "run like hell."

As the White House looks to private companies to invest heavily in American infrastructure, this pair of cities offers a unique window into the perks and perils of private dollars in public infrastructure.

Missoula’s fight to go public

Montana's second-largest city has unusually long experience with a private corporation being in charge of its infrastructure: The water authority had been fully privatized since at least the 1930s.

Engen said the city had long harbored concerns about the authority being privately owned, but those worries increased exponentially after Park Water, the family-run business that had managed Missoula’s system for decades, was sold to a global private equity firm, Carlyle Group, for $102 million in 2011.

Under Carlyle, rates rose and deferred maintenance piled up, the city later testified in court. Carlyle Group disputed the city’s claims, and testified that it was budgeting $4 million a year for repairs.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

naumoid / Getty Images/iStockphoto

"During Carlyle’s ownership, capital expenditures more than doubled, leakage was reduced, water quality was excellent and employment was stable," the firm told NBC News in a statement Monday.

Engen said the city feared future rate hikes and what would happen if Carlyle sold the investment to another corporation.

“It became clear to us that this water system had become a commodity rather than a community resource,” Engen said. The city offered Carlyle $65 million to buy the water system, which the firm rejected. Missoula then filed an eminent domain suit to force the sale in 2014, arguing in court that the municipality’s long-term interest in the water system was best because they weren’t trying to turn a profit.

The court agreed.

“Given the inevitability of future rate increases due to needed capital investment in an aging Water System and costs of acquisition, the Court considers that municipal ownership is more necessary than private ownership,” U.S. District Judge Karen Townsend wrote in a preliminary order of condemnation, the Montana process that begins valuation and a forced sale.

Six months later, however, before court proceedings could finalize the sale, Carlyle left town with a profit: They sold Park Water to Liberty Utilities for $327 million, without state approval. The court-forced sale continued nonetheless, with the city spending nearly $100 million on fees and the ultimate purchase of the utility from Liberty.

These days, the water system still leaks a lot — it’s not much better than it was eight months ago, when the sale closed, Engen said — but the city has already made $6 million in repairs and is working hard to stop the system from leaking half its water back into the ground.

“We’re bound and determined to get that to an industry standard of 15 percent or better,” he said.

Rialto’s path toward public-private partnership

In 2012, Rialto needed a new wastewater plant and a slew of costly repairs to their aging water system, but didn’t have the cash.

“There’s no way we could have done it without going into major debt,” Scott, the mayor pro tem, told NBC News.

Enter a public-private partnership: a group of investors lead by Table Rock Infrastructure Partners paid the city $30 million, along with a $2 million annual payment, and invested heavily in the water system itself, to the tune of $41 million. The deal was the first public-private partnership of its kind, Table Rock said, though they said they're in talks with 25 other cities about similar deals, including Wichita, Kansas, and Pittsburgh. Unlike Missoula’s full privatization, Rialto maintained ownership and control of rate hikes, while handing over the rights to maintenance and management to the private investors.

For smaller water authorities like Rialto’s who might not have the money for climate change experts or the experience doing a major wastewater plant upgrade, outside investors bring a wealth of knowledge, Megan Matson, a Table Rock partner, said.

Rates went up significantly under the new deal, but Scott said a campaign of voter education helped people understand why. Hiring a city employee to liaison and oversee the privately run authority helped, too.

The influx of cash was used to redevelop an old airport for industrial, retail, commercial and residential use, helping to bring a Cinemark theater, Burlington Coat Factory and Starbucks to the space, Engen said. Much of those economic redevelopment costs have been recouped as developers move into the space, too, allowing the city to use it elsewhere.

"Elected leaders are so gun-shy on doing anything about rates," Matson said. "It’s going to cost some money. There’s that idea that water is a human right and water should be free. Yes, but the pipes to get it and the plant to treat it and the people responsible for running it — they’re not free."

The contract capped private investors’ returns and incentivized a long-term partnership instead of a quick return. If the profits are better than expected, the surplus goes to the city, Matson said.

"When we’ve hit points of disagreement, we look at the contract and the contract says sit back down and keep talking. The contractual structure is really everything," she said. "If the incentive structure is to stick around and stay partnered through thick and thin, you’re going to reap the benefits."