BOSTON — The city of Boston has agreed to pay more than $2.1 million to the Christian legal organization that backed a court challenge after the city refused to fly a Christian flag outside City Hall, a case that made it all the way to the U.S. Supreme Court.

The settlement announced Tuesday by Liberty Counsel covers attorneys’ fees and other costs associated with the legal battle that started in 2017 when city resident Hal Shurtleff and his Camp Constitution group asked to hoist the flag on one of three poles on City Hall Plaza to mark Constitution Day.

“We are pleased that after five years of litigation and a unanimous victory at the U.S. Supreme Court, we joined with Hal Shurtleff to finally let freedom fly in Boston, the Cradle of Liberty,” Liberty Counsel founder and Chairman Mat Staver said in a statement.

The U.S., state and city flags usually fly outside the building, but the city flag is sometimes taken down and temporarily replaced with another.

Between 2005 and 2017, the city approved 284 consecutive applications from private organizations to fly flags, with no denials, before it rejected Shurtleff’s proposal, Liberty Counsel said.

The Supreme Court unanimously ruled in May that the city violated the free speech rights of Shurtleff because of his “religious viewpoint.”

The Christian flag — which is white, with a red cross on a blue background in the upper left corner — finally flew for a couple hours outside City Hall on Aug. 3 as activists cheered and sang songs of praise.

The city has since passed an ordinance that clarifies the rules for flag raisings.

Liberty Counsel was entitled to attorneys’ fees as the prevailing party in the case, the city said in a statement.

The city’s Law Department determined $2.125 million to be reasonable based on billing statements provided by Liberty Counsel and through their own analysis, the statement said.

“Settlement at this time also allows the City to avoid the costs and uncertainty associated with further litigation in this case,” the city statement said.

The case has established precedent, Liberty Counsel’s Staver said, “including the overturning of the 1971 ‘Lemon Test,’ which Justice (Antonin) Scalia once described as a ‘ghoul in a late night horror movie.’ The case of Shurtleff v. City of Boston finally buried this ghoul that haunted the First Amendment for 51 years.”