In Madrid's supreme court one of the world's best-known human rights investigators, the Spanish magistrate Baltasar Garzón, has been on trial. Although he was found innocent of abusing his powers, the court still declared that he had been wrong to open an investigation into murderous repression in the Spain conquered, and then ruled by, dictator General Francisco Franco and his fascist-backed rebels.

The trial of Garzón at the behest of pro-Francoists and the Falange – which manned death squads during Spain's bloody civil war in the 1930s – is a reminder of Spain's thorny relationship with its past. Conservatives such as former prime minister José María Aznar want legislators and judges to leave the generalísimo and his cronies alone. "In the democratic transition there were implicit and explicit agreements. One was that we Spaniards don't want to look to the past," he says. "Let's not disturb the graves and hurl bones at one another. Let the historians do their job."

That is what Paul Preston, a leading British hispanicist and highly respected historian in Spain, has done in The Spanish Holocaust. The result is an essential read for anyone wishing to understand Spain and its recent history. It is also a damning indictment of Franco's deliberate and far-reaching brutality, which destroys the myth cherished by some Spaniards that he was a "soft" dictator.

One of the many remarkable things about this narrative of butchery is, indeed, how it proves Garzón's central accusation – that Franco enacted a ruthless plan involving the "detention, torture, forced disappearance and physical elimination of thousands of people for political and ideological motives … a state of affairs that continued, to greater or lesser extent, after the civil war ended".

Preston provides facts, figures and harrowing descriptions in the first full and proper attempt to explain the horror. He does not shy away from strong words – "holocaust" is deliberately chosen to describe the extent of cold-blooded killing "because its resonances with systematic murder should be evoked in the Spanish case, as they are in those of Germany or Russia". Nor does he ignore the undoubted cruelty and the crimes committed on the Republican side of a three-year civil war sparked by a 1936 military rightist uprising against an elected government. Two-thirds of the clergy in the Catalan province of Lleida were killed. A third of all monks in the Republican zone also died. That is extreme religious persecution.

It was a cowardly war where more people died away from the front than on the battlefield. The often casual nature of the violence makes numbers hard to pin down, but some 200,000 people were killed by death squads, vigilantes, village rivals or firing squads – perhaps a quarter in the Republican zone. The victor prolonged his revenge, liquidating 20,000 opponents after the war, and condemning hundreds of thousands to prison, exile, ostracism or poverty as Franco made a calculated investment in terror.

Preston establishes key differences between the two sides. Under Franco's command, terror was official policy. In Republican Spain, with some glaring exceptions, it was more often the result of chaos, fear, ignorant hatred, criminal thuggery and anarchy (often with a capital A, as unleashed by the church-hating Confederación Nacional del Trabajo). It was also usually – but not always – heavily curtailed once law, order and central authority were established.

Preston charts the prejudice that led Spain's reactionary right into this bloodletting. Decades of dictatorship, and the ensuing silence after Franco's 1975 death, have kept this out of Spanish minds. Only over the past decade, as campaigners have dug up mass graves, has a desire for knowledge burst through. As a result, Preston can turn to new local studies.

He sees two main drivers behind the slaughter. The first was the absolute, and often paranoid, conviction of radical rightists that the enemy was evil. Democrats, reds, Jews, freemasons, Marxists, Muslims, "free" women, trade unionists, socialists, socially concerned priests and social liberals were, simply because of their beliefs, considered to be guilty of crimes against the fatherland, God and the natural social order. Franco believed in an entirely imaginary "Jewish-masonic-Bolshevik" plot against Spain. The Falangist Onésimo Redondo thought "Mohammedan utopias" were also to blame.

A second driving force was the brutalisation of Spain's colonial army in Africa, where Franco had made his name. This army was used to fighting north African Muslims it viewed as sub-human. It was no great leap to see Spain's own politicised landless labourers as "Berbers and savages". That made it easy for Franco and generals such as Emilio Mola or Gonzalo Queipo de Llano to pursue not just victory, but annihilation. "It is necessary to spread terror, eliminating without scruples or hesitation all those who do not think as we do," said Mola. "All those who oppose the victory of the movement to save Spain will be shot."

An early taste came in Badajoz. Hundreds, if not thousands, of prisoners were machine-gunned to death in the city's bullring. Rightists came to watch and cheer. The brutality drove one Portuguese witness to madness. Nearly 10% of the city's population of 40,000 was killed following the seizure of the town. People far from the frontline were treated just as savagely. "Here there is no battlefield shooting or taking of prisoners, but instead the most bestial persecution and unjustified murders," wrote Miguel de Unamuno, the Spanish philosopher who had initially backed the rebellion, from the university city of Salamanca. "It is a stupid regime of terror."

Anarchist excesses on the Republican side – perpetrated by murderous outfits such as the Lynxes, the Death Brigade and the Dawn Squad – completed the vicious cycle. The horrors of Badajoz fed the "red terror" of Madrid (including the notorious killing of more than 2,000 prisoners at Paracuellos del Jarama), which then encouraged greater Francoist brutality.

Life became a cheap commodity. The casual way in which victims were put to death is revealed in the case of the poet Federico García Lorca and the humanist Agustina González Blanco. "We killed him for being a queer and her for being a whore," said one rightist. Franco's obsession with freemasons saw 100 people killed for belonging to a masonic lodge in Huesca which had only five members.

Rape, humiliation and sexual abuse of women was common. "They'll not live more than four hours," said a Francoist officer as two teenage girls deemed leftists were pushed into a schoolhouse with 40 soldiers.

By the end of the war more than 370,000 prisoners were being held. In Franco's upside-down world, defenders of the legitimate, elected government could be executed for "military rebellion". Laws were passed allowing for the trial of those who had held positions of responsibility in the two years before the uprising – for breaking laws that did not exist at the time. Even the dead could be fined and their widows forced to pay.

Preston follows the repression to the early 1950s. Others will have to provide the story of later Francoism, a period some conservatives recall as "extraordinarily placid" (as Aznar's former interior minister Jaime Mayor Oreja put it). Preston's excellent, spine-chilling narrative, however, explains just how deep Franco's early investment in terror was and, as a result, why he was able to draw on it for decades.

Franco had time to impose his own version of history, which still prevents contemporary Spain from "looking upon its recent violent past in an open and honest way", writes Preston. He is only too aware of the hysterical reaction to Garzon and those who break the taboo of interrogating the past. The fierce criticism of the truth-seekers is, he says, a long-term consequence of the brainwashing that turned many Spaniards into Francoists or, at least, adherents of what Spaniards call "sociological Francoism". "It lives on in the democratic Spain of today," Preston warns, just as "sociological communism exists in the countries of the old Soviet bloc." That is an uncomfortable thought for a country now facing its toughest period since the caudillo's death. But this is an invaluable book that does not shrink from even the harshest of truths.

• An updated edition of Giles Tremlett's Ghosts of Spain is published by Faber on April 5.