The Sagrada Familia basilica in Barcelona, one of Spain’s most famous tourist sites, has agreed to pay $41m (£31m) to the city authorities after going without a building permit for more than 130 years.
The spectacular church designed by architect Antoni Gaudí, is a Unesco world heritage site and still under construction.
Work began on the building in 1882.
Barcelona’s mayor said the deal was a historic agreement.
The basilica will pay the money over 10 years to improve public transport and access to the monument and assist the local neighbourhood.
In return its status should be regularised early next year, Mayor Ada Colau said.
About 4.5 million people visit the Sagrada Familia each year, with a further 20 million people visiting the area to look at it.
The main structure is due to be completed by 2026, the centenary of Gaudí’s death.