The City of Philadelphia must pay nearly $900,000 to the Boy Scouts for legal fees after failing to evict the scouts from their headquarters over antigay policies.

A federal judge on Wednesday denied the city’s request for a new trial in a case that has lasted    nearly a decade. Mayor Nutter said the city was reviewing the opinion, calling the $877,122 bill a “significant expense.”

The city tried to avoid a giant payout by proposing a deal last year in which the local Cradle of Liberty scouts group would buy the building at 22d and Winter Streets for $500,000 and forgive the legal fees. But legislation to authorize the deal languished in City Council after gay-rights advocates complained.

The city tried to evict the scouts over the national organization’s policy of excluding gays, but the scouts sued. Ever since the scouts’ legal victory in 2010, the two sides have been trying to work out a settlement.