Leo called Gaudi's unfinished temple, one of the world's most visited monuments, a "sign of unity and harmony for all of Spain," an ongoing building project like the lifelong journey all Christians make to find God.
"We are all the living stones of this edifice," Leo said from the altar of the basilica, with Spanish King Felipe VI and Queen Letizia sitting to his side and a hundreds-strong choir filling the soaring basilica with song.
The service marked the highlight of Leo's weeklong visit to Spain, the first by a pontiff in 15 years to the once staunchly Catholic European country that, like many others, has experienced secularising trends.
The trip, though, has underscored how the country of 50 million people, which experienced a religious crisis after its 20th century dictatorship ended, still has plenty of faithful Catholics who have turned out in droves to welcome Leo.
Tens of thousands of people lined the streets around Sagrada Familia for the event, with streets closed to traffic and a heavy police presence, given the attendance of the royal couple and Prime Minister Pedro Sánchez.
The crowds remained to watch a light show that was to accompany Leo's consecration of the basilica's final Tower of Jesus Christ that has made it the world's tallest church.
"The entire structure of the Sagrada Familia is striking," said Laura Rincón, who was on hand outside along with two friends for the Mass, after she finished work in a nearby shop.
She said that she was sure the Pope would be impressed by the church she marvels at every time she passes by.
"If you look at it just for its architecture, it is amazing," she said.
"Inside, its columns make you feel like you are inside a forest."
Earlier on Wednesday, Leo celebrated a more ancient sacred monument, travelling to Montserrat, a mountain complex outside the city that is dear to many Catalans.
The complex, which includes an 11th-century Benedictine abbey and a 16th-century basilica, is revered for its Black Madonna statue and is home to a boy's choir that has existed since the 13th century and is Europe's oldest.
Thousands of faithful arrived early at the monastery, with groups of nuns and schoolchildren singing and waving signs and photographs of the pope outside the basilica.
Bells rang out over the spire-like rock formations that top Montserrat and the valley below as Leo arrived in a golf cart.
In recent years, the Montserrat abbey has faced numerous accusations from survivors of clergy sexual abuse and was included in the Spanish ombudsman's 800-page report on the crisis in 2023.
The report found 15 victims and three alleged perpetrators linked to the abbey.
"It's very painful because there are members of the church who committed errors," said the Reverend Cesario Escarda, a Toledo priest, as he waited for Leo at the abbey.
"What the Pope wants to do is shine a light on the truth and ask forgiveness and bring in the victims and listen to them and accompany them."
The highlight of Leo's visit, though, was his Mass at Sagrada Familia to commemorate the 100th anniversary of the death of its famed Catalan designer, Gaudí, who died at age 73, three days after he was hit by a tram.
A century after construction began during the pontificate of Leo's namesake, Pope Leo XIII, the basilica has become one of the world's most visited but unfinished monuments, annually drawing upward of five million visitors a year.
Commemorating Gaudí's death, Leo said he wanted to give thanks to all the supporters, artists and workers who "co-operated in the construction of an architectural masterpiece, which is also an eloquent catechesis made of stones, colours and light".