Spain's supreme court ruled on Tuesday in favour of exhuming the remains of former dictator Francisco Franco and moving them from the state mausoleum in which he was buried in 1975.
The ruling could end decades of controversy over the burial place of the man who still divides opinion in Spain, 80 years after the end of the 1936-1939 civil war he unleashed and nearly 44 years after his death.
The government of Socialist Pedro Sanchez can now go ahead with plans to move the remains from the Valley of the Fallen mausoleum near Madrid to Mingorrubio El Pardo, a state cemetery on the outskirts of the capital where his wife is buried.
The Socialists have long sought to turn the Valley of the Fallen complex into a memorial to victims of the civil war, in which about 500,000 people were killed.
Nearly 34,000 dead from the civil war are buried there, including many who fought for the losing Republican side and whose bodies were transferred to the site during Franco's dictatorship without the permission of families.
"This is a great victory for Spanish democracy," acting Prime Minister Pedro Sanchez said.
"The determination to repair the suffering of the victims of Franco always guided the action of the government."
Deputy Prime Minister Carmen Calvo said the exhumation would be carried out "as soon as possible" but gave no date.
Spain is facing its fourth election in four years in November and moving Franco's remains from the state mausoleum has long been a Socialist pledge.
Relatives and friends of victims of Franco, who ruled Spain for almost 40 years, gathered outside the Supreme Court brandishing pictures of loved ones.
They welcomed the ruling but said efforts must continue to exhume people from mass graves where many still lie anonymously.
"It's a small victory but so much more needs to be done," said 55-year old Marisa Perez.
Franco's family had appealed against exhuming his remains and against the government's plans to move them to the El Pardo cemetery. They had said that if his remains were to be moved, they should go to the Almudena Roman Catholic Cathedral adjacent to the Royal Palace in central Madrid, alongside his daughter.
The court rejected their demands.
"The fourth section of the third chamber has unanimously agreed to dismiss in its entirety the appeal filed by the family of Francisco Franco in relation to the exhumation of Francisco Franco agreed on by the government," the court statement said.
A lawyer for the family of Franco said they would make further appeals, including to European courts, but a government source said the exhumation could now go ahead.
"This is a violation of personal and family rights ... with a government prohibiting a family from burying one of its members where it wants," lawyer Felipe Utrera Molina told TVE.
A government report said last December that the Almudena cathedral was unsuitable as a burial place for security reasons.
In an effort to ease the transition to democracy after Franco's death, Spain passed an amnesty law pardoning political crimes committed during the conflict and the dictatorship in an accord known as the "Pact of Forgetting".