The Supreme Court ruled on Monday that the city of Miami can sue Bank of America and Wells Fargo under federal housing law for allegedly engaging in discriminatory lending practices toward minority borrowers. But in the same ruling, it set a high bar for cities claiming that they too were victims, down the road, of that discrimination.

In its lawsuit, filed in 2013, Miami contended that the two banks’ targeting of prospective black and Latino homeowners for riskier, less favorable mortgage loans ultimately drove a wave of defaults, foreclosures and a fall in property values in the city. As a result, Miami argued, it was left with less tax revenue and a rash of blighted homes that forced it to funnel more municipal resources into the affected communities.

The Supreme Court held in a 5-to-3 decision that Miami counts as an “aggrieved person” under the Fair Housing Act and therefore may use the law to pursue its claims against the banks.

“Here, we conclude that the City’s claims of financial injury in their amended complaints — specifically, lost tax revenue and extra municipal expenses — satisfy the ‘cause-of-action’ ... requirement” in the law, wrote Justice Stephen Breyer.

He explained that other localities and nonprofit groups had previously been permitted to rely on the Fair Housing Act to sue over financial injuries, and that Congress had nonetheless chosen not to rewrite the law to prohibit lawsuits by such entities.

Breyer was joined in the majority by Chief Justice John Roberts and Justices Ruth Bader Ginsburg, Sonia Sotomayor and Elena Kagan. A host of civil rights groups, localities, legal scholars and the Obama administration supported Miami’s stance in the case.

The ruling, however, wasn’t a slam dunk for Miami. The justices sent the case back to a lower court to determine whether Bank of America and Wells Fargo’s lending practices were indeed the “proximate cause” of Miami’s losses.

The difficulty here is that “the housing market is interconnected with economic and social life,” the Supreme Court said. Acts of housing discrimination may have ripple effects far beyond what Congress intended to address in the Fair Housing Act.

“Nothing in the statute suggests that Congress intended to provide a remedy wherever those ripples travel,” Breyer wrote. “And entertaining suits to recover damages for any foreseeable result of an FHA violation would risk massive and complex damages litigation.”

In a separate opinion that partly agreed and partly disagreed with the majority, Justice Clarence Thomas all but predicted that Miami won’t be able to show that the banks’ lending practices led to its troubles ― largely because there are far too many other factors separating cause and effect.

“In light of this attenuated chain of causation, Miami’s asserted injuries are too remote from the injurious conduct it has alleged,” Thomas wrote. In his view, the city’s diversion of more municipal resources to certain neighborhoods had nothing to do with preventing housing discrimination, which is the purpose of the Fair Housing Act.

For the same reason, Thomas added, the law wouldn’t allow homeowners who didn’t face foreclosure to sue the banks for unleashing urban blight that might drive down their property values.

Thomas’ opinion was joined by Justices Anthony Kennedy and Samuel Alito. Justice Neil Gorsuch, who wasn’t on the court when it heard the case in November, didn’t participate in the decision.

Miami officials welcomed the ruling. “We look forward to litigating this case further in the Trial Court,” City Attorney Victoria Mendez said in a statement.

Bank of America spokesman Lawrence Grayson similarly referenced the ongoing litigation. “Bank of America is committed to the goals and intent of the Fair Housing Act. We believe these claims are without merit and we will continue to defend our interests in this matter,” he said.

Tom Goyda, a spokesman for Wells Fargo’s consumer lending unit, sounded a more confident note.

“We believe that under the stringent standards articulated by the Supreme Court, it will be very difficult for Miami or any other municipality to show the required connection between the claimed damages and unsubstantiated allegations about our lending practices, which do not reflect how we operate in the communities we serve,” Goyda said in a statement.