More than a century after its first stone was laid and 92 years after its famously ascetic architect was fatally struck by a tram, the Sagrada Familia in Barcelona is finally getting its paperwork in order.

A deal between the church’s trustees and the city council means the project, on which construction began in 1882, will be granted a building licence for the first time.

Antoni Gaudí’s unfinished masterpiece is Barcelona’s most visited tourist site, attracting 20 million visitors to the area each year. But until Thursday it had lacked the proper permissions.

The new agreement will formalise the building works and pave the way for a plan “to study the urban solutions in order to finish Antoni Gaudí’s project”, the city council said.

The deal includes schemes to improve public transport and the surrounding area. The Sagrada Familia will pay €22m (£19.3m) to help underwrite the city’s transport network, including €7m to improve accessibility on the Barcelona metro system. Four million euros will be invested in renovating four major thoroughfares and €3m will be for keeping streets safe and clean.

“The Sagrada Familia is an icon and the most visited monument in our city,” the Barcelona mayor, Ada Colau, said in a tweet. “After two years of dialogue we have made an agreement that will guarantee the payment of the licence, secure access to the monument and facilitate local life with improvements to public transport and redevelopment of the nearby streets.”

Work on the Sagrada Familia began in March 1882, based on a neo-gothic design by the architect Francisco de Paula del Villar y Lozano. When he resigned shortly afterwards, Gaudí stepped in with perhaps his most famously idiosyncratic design.

The church quickly became the life’s work of the Catalan architect. He oversaw construction between 1883 and early June 1926, when he was hit by a tram. He succumbed to his injuries three days later and was buried, fittingly, in a chapel in the Sagrada Familia’s crypt.

Gaudí’s collaborator Domènec Sugrañes took over the project, adhering to Gaudí’s original concept. During the Spanish civil war the studio workshop burned down and original plans, drawings, photographs and models were destroyed, but the work went on.

With luck it will finish in eight years’ time – the centenary of Gaudí’s death and a mere 143 years after it began.