Pope John Paul II was greeted in Madrid today, at the start of the first visit to Spain by a reigning pontiff, with a mix of official pomp and joyous scenes of popular enthusiasm.

The frenzy of the huge crowds that lined the seven-mile route from Barajas airport to the capital's main Castellana Boulevard contrasted with the somewhat muted sense of expectancy that has fallen on Spain since the Socialist Party won a landslide parliamentary election victory Thursday.

Earlier the pope had kissed the airport runway, as is his habit, and had risen unaided. As a 21-gun artillery salute boomed across the airfield, the bells of every church in the land broke into sustained peals.

King Juan Carlos, who greeted John Paul with a handshake, said in a welcome address that the 10-day papal visit came at a moment of national "anxiety but also of hope," because "Spain is determined to live in harmony." Queen Sofia dropped to her knees to kiss the pontiff's ring as did all the members of the outgoing centrist administration that remains as a caretaker executive until the Socialists formally take office in December.

In his prepared statement, the pope urged Spanish Catholics to recover their religious vigor and faith and said this would be one of the principal aims of his trip, which will take him to 16 cities and small towns.

"Let the pope speak," he said smilingly to silence the cheering at the airport. He reminded his listeners that Spain historically had acted as a principal buttress of Roman Catholicism and he praised Spain's missionary zeal in earlier ages. His remarks appeared to indicate a close identification of the pope with a Spanish bishops' report, issued to coincide with the visit, that complained of falling church attendance, few vocations for the priesthood and increasingly lax moral standards.

As the drive to Madrid got under way, the crowd showered the pope with yellow and white carnations, the Vatican colors.

For hours, the crowd had been singing, strumming guitars and clapping hands in what amounted to a religious carnival that brought together large numbers of teen-agers as well as older people and what appeared to be thousands of nuns.

The visit comes at a fascinating crossroads in Spain. Originally scheduled to take place last year, but delayed because of the assassination attempt against the pope, it was postponed again last month to prevent the trip becoming entangled in the electoral campaign. As a result, the pontiff has arrived following the Socialist triumph after 40 years of that party's persecution, exile and opposition.

The political coincidence of the trip has provoked considerable comment in the Spanish press. The prestigious, liberal Madrid newspaper El Pais noted in an editorial today the possible areas of conflict between the pope's persistent drive to increase the projection of the church in society and the Socialists' stated aim to modernize, and, by extension, secularize Spain.

Specific issues separating the incoming Socialist government and the Spanish religious authorities include plans for a relaxation of bans against abortion, public funding of contraception and new education guidelines that some Catholics say could constrain religious teaching in schools.

Prime Minister-elect Felipe Gonzalez, who is a lapsed Catholic, is expected to meet the pontiff at a reception given by the king.