The city must pay nearly $900,000 after a failed effort to evict the Boy Scouts of America because of the group's ban on gays, a federal judge ruled Wednesday.

The post-trial ruling is just the latest twist in a decade-long legal dispute over the Boy Scout oath, which requires members to be "morally straight."

The two sides have sought a compromise that would let the local Boy Scouts chapter keep its rent-free, city-owned headquarters without violating the national Scout policy.

However, a tentative deal struck since the city lost a court case last year has fallen apart. U.S. District Judge Ronald Buckwalter therefore said the city must pay $877,000 for the Scouts' legal fees.

The order is a setback for the financially strapped city. City Council passed on a proposed deal to resolve the conflict _ and avoid paying the legal fees _ by selling the Scouts the building for $500,000, Mayor Michael Nutter told the Philadelphia Daily News.

"We do not as a city support that kind of behavior," Nutter said Wednesday. "We've tried to take a number of steps to get the Boy Scouts out of a city-related building."

The city insisted at a June 2010 trial that nonprofits given free use of its property must abide by local anti-discrimination laws, which include equal protection for gays. But the jury found the city's reason violated the local Scout council's First Amendment rights.

"The city defended this suit in a very principled way," Buckwalter said after the verdict.

The local Cradle of Liberty Council has tried to walk a fine line between appeasing the city, the United Way and other supporters and the Irving, Texas-based Boy Scouts of America.

In 2003, it enacted its own nondiscrimination policy but was forced to repeal it when the Boy Scouts of America ordered it to conform to national rules. The chapter later enacted a statement that says it doesn't tolerate illegal discrimination.

There has been just one known case of a gay Scout being ousted from the Philadelphia chapter, although the city argued that more were perhaps scared off by the national policy.