Álvarez was born in Granada. He joined the army in 1768, and studied at the Military Academy of Barcelona, graduating in 1775. He gained steady promotions, saw action in the siege of Gibraltar in 1783, and by 1793 was a Colonel of Infantry. During the War of the Pyrenees against France he took part in many notable actions, was wounded, and spent 75 days under fire at the siege ofCollioure. As a result, he was promoted to Brigadier. On the accession of Joseph Bonaparte to the throne of Spain in 1808, Álvarez was commander of the castle of Montjuïc in Barcelona. On 29 FebruaryFrench troops arrived to take possession of the fortress. Álvarez was preparing to defend it against them when he received direct orders of his Commander in Chief to hand it over. Álvarez fled Barcelona and joined the Spanish rebels against French rule. The Cortes of Cádizwhich served as a parliamentary Regency after Ferdinand VII was deposednamed Álvarez commander of the Army of Catalonia and Governor of Girona.
Siege of Girona
On the 6 May 1809 a French army of 18,000 men besieged the town. Álvarez had only 5,600 men under arms. The French mounted 40 gun batteries that over the next seven months fired some 20,000 explosive shells and 60,000 cannonballs into the city. In August, the French captured the castle of Montjuïc, the main defensive point. Undeterred, Álavarez constructed barricades and trenches inside the city and battle raged for another four months before Álavarez, exhausted and ill, handed over command to a subordinate. Two days later, on 12 December, the town capitulated. It is estimated that some 10,000 people, soldiers and civilians, had died inside. French losses were around 15,000, over half of those to disease.
Death
In spite of Álvarez's poor health, the French imprisoned him at Perpignan. On 9 January 1809 Álvarez was brought to the castle of San Fernando in Figueres, where he was found dead the following day, of a fever according to the French, poisoned, according to the Spanish. He was buried, wrapped in only a sheet, in the cemetery there.
Posthumous honours
He was posthumously promoted to Field Marshal in April 1809 and made a Commander of the First Battalion of the Spanish Royal Guards Regiment in May 1810. In 1815 a black marble tablet was placed on his grave which stated that Álvarez had been poisoned, and was a Victim of the Iniquity of the French Tyrant. In December 1823 French troops, ironically invading Spain in order to restore the tottering throne of Ferdinand VII, passed through Figueres, and on the orders of Marshal Moncey, formerly Napoleon's Inspector-General of Police, destroyed the plaque. In 1880 a funerary monument, sculpted by Jeronimo Suñol, was erected in the Church of San Felix in Girona. In 2010, around the 200th anniversary of his death, an exhibition Álvarez de Castro y su tiempo was held in his honour at the castle of San Fernando in Figueres.