A congregation estimated at one million people spread out along four boulevards intersecting at Plaza de Colon, where a huge white altar was erected for the canonization Mass.
The ceremony honored two priests and three nuns, 20th century Spaniards honored for their work with the poor. Giant pictures of the five hung from an office building overlooking the plaza.
"We inscribe them in the book of the saints, and establish that in all the church they be devoutly honored among the saints," the pope said in Spanish.
Later, in his homily, John Paul said: "Beloved Catholics of Spain, let yourselves be inspired by these marvelous examples."
He urged Spain's Catholics to embrace the faith. "Christian and Catholic faith constitute the identity of the Spanish people," he said.
The canonization was the centerpiece of ailing John Paul's weekend visit, his fifth to Spain and first outside Italy in nine months.
The archbishop of Madrid, Cardinal Antonio Maria Rouco, has said this is probably the pope's last trip to Spain. John Paul turns 83 this month and shows symptoms of Parkinson's disease. He moves on a trolley because knee and hip ailments make it hard for him to walk.
The pope drew more applause as he closed the nearly three-hour Mass saying, "with open arms, I carry you all in my heart."
"With great affection," he added, "farewell, Spain."
One of the canonized priests, Pedro Poveda, was killed in 1936 during the opening days of the Spanish Civil War.
The church says 4,184 clergy were killed during the war by the government, or Republican, side, which accused the church of backing fascist Gen. Francisco Franco.
The other four new saints are Angela de la Cruz, who founded the Sisters of the Company of the Cross; Genoveva Torres, who founded the Sisters of the Sacred Heart and of the Holy Angels; Maravillas de Jesus, who founded convents for the Order of Barefoot Carmelites, and Jose Maria Rubio, a Jesuit priest.
Sunday's service raised to 469 the number of saints John Paul has proclaimed in his nearly 25-year papacy. He has proclaimed more saints than any other pontiff.
Spanish church officials hoped the visit will reinvigorate a flock that has seen many ignore Catholic teachings since Franco's death in 1975. The dictator worked closely with the church to encourage strict adherence to doctrine.
Only about a quarter of Spain's Catholics go to church once a month, polls show, while about half acknowledge they almost never attend Mass.
In the crowd, people carried banners or pictures of their favorite saints.
Magdalena Abedaro, a 55-year-old midwife from Cadiz in the southern Andalusia region, said her favorite saint was Angela de la Cruz because she came from nearby Seville and had performed many miracles.
"One woman in my hospital who has been in a coma for three months was saved by Angela de la Cruz," Abedaro said.
The plaza filled long before the Mass with worshippers carrying beach chairs, binoculars and sandwiches, playing tambourines and singing.
"I love to see the pope. It makes me feel renewed," said Nuria Moreno, 68. "I don't need to touch him or hear him. Seeing him is enough."
Eight giant TV screens were set up around the plaza for people to watch the Mass, and communion was distributed by 1,500 priests shuttling around in minibuses.
The five new saints were beatified in the 1980s and 1990s. Beatification requires evidence of a miracle after the person's death. Sainthood requires evidence of a second miracle.
At Sunday's Mass, sitting near the altar, were five people who the church claims experienced such miracles.
One was Antonio Diez, a 51-year-old army lieutenant who fell into a coma at Christmas in 1971 because of complications from a stomach ulcer. The church says he was cured after his family prayed to Genoveva Torres.
The pope made world peace a theme of the first day of this weekend visit, the highlight of which was a meeting with an estimated 600,000 youths — double the church's prediction — at an air base outside the city.
The pope was scheduled to return to Rome Sunday evening, after having lunch with senior members of the Spanish Bishops Conference and meeting with King Juan Carlos.