Nobody casts a longer shadow over Spanish politics than Franco, even decades after his death in 1975. Almost every aspect of his legacy has fueled dispute, extending recently to the renaming of squares and streets associated with his regime. Some cities controlled by left-leaning politicians want to carry out other exhumations, notably in Seville, where one of Franco’s military commanders, Gonzalo Queipo de Llano, was also buried in a basilica.

Paul Preston, a British historian and biographer of Franco, said that Spain was an anomaly in Europe in keeping a “place of pilgrimage for its fascist dictator” — there are no monuments to Adolf Hitler in Germany or in Austria, nor to Benito Mussolini in Italy. Among the more than 250,000 visitors to the Valle de los Caídos each year, Mr. Preston said, many are devotees of Franco “brought up to believe that he was a benefactor for Spain.”

Mr. Sánchez, the prime minister, leads a fragile Socialist government that has only a quarter of the seats in Parliament.

But he could order Franco’s removal by decree. The exhumation plan — which was proposed a decade earlier by the previous Socialist prime minister, José Luis Rodríguez Zapatero — is likely to win support from the leftist Podemos party and from Basque and Catalan nationalist lawmakers who joined forces with Mr. Sánchez to allow him to replace Mr. Rajoy.

Franco decided to carve the basilica into the mountainside shortly after winning the civil war. Construction lasted 18 years, with Republican prisoners among the labor force. The basilica also became the resting place of several nuns and other members of the clergy killed during the civil war — some of whom were later beatified by the pope — as well as that of José Antonio Primo de Rivera, the leader of the far-right Falangist party, who was killed in 1936 and was considered a martyr by Franco’s followers. His tomb is on the other side of the altar to that of Franco.

Last month, Mr. Sánchez met with Archbishop Ricardo Blázquez of Valladolid, the leader of the confederation of Spanish bishops. After the meeting, the Rev. José María Gil Tamayo, the secretary general of the confederation, suggested that the church would prefer to stay on the sidelines of what it considered to be a political debate over Franco’s remains.