Castelar was born in Cadiz. He was an eloquent and literary man. He was appointed dictator of Spain in 1873, but not being equal to the exigency in the affairs of the state, he resigned, and made way for the return of monarchy, though under protest. He wrote a history of the Republican Movement in Europe among other works of political interest.
Before the revolution of 1868, Castelar had begun to dissent from the doctrines of the more advanced republicans, and particularly as to the means to be employed for their success. He abhorred bloodshed, disliked mob rule, and did not approve of military pronunciamientos. His idea would have been a parliamentary republic on the American lines, with some traits of the Swiss constitution to keep in touch with the regionalist and provincialist inclinations of many parts of the peninsula. He would have placed at the head of his commonwealth a president and Cortes freely elected by the people, ruling the country in a liberal spirit and with due respect for conservative principles, religious traditions, and national unity. Such a statesman was sure to clash with the doctrinaires, like Salmeron, who wanted to imitate French methods; with Pi y Margall, who wanted a federal republic after purely Spanish ideas of decentralization; and above all with the intransigent and gloomy fanatics who became the leaders of the cantonal insurrections at Cadiz, Seville, Valencia, Málaga, and Cartagena in 1873.
At first Castelar did his best to work with the other republican members of the first government of the federal republic. He accepted the post of minister for foreign affairs. He even went so far as to side with his colleagues, when serious difficulties arose between the new government and the president of the Cortes, Señor Martos, who was backed by a very imposing commission composed of the most influential conservative members of the last parliament of the Savoyard king, which had suspended its sittings shortly after proclaiming the federal republic. A sharp struggle was carried on for weeks between the executive and this commission, at first presided over by Martos, and, when he resigned, by Salmeron. In the background Serrano and many politicians and military men steadily advocated a coup d'etat in order to avert the triumph of the republicans. The adversaries of the executive were prompted by the captain-general of Madrid, Pavia, who promised the co-operation of the garrison of the capital. The president, Salmeron, and Marshal Serrano himself lacked decision at the last moment, and lost time and many opportunities by which the republican ministers profited. The federal republicans became masters of the situation in the last fortnight of April 1873, and turned the tables on their adversaries by making a peaceful bloodless pronunciamiento.
The battalions and the militia that had assembled in the bullring near Marshal Serrano's house to assist the anti-democratic movement were disarmed, and their leaders, the politicians and generals, were allowed to escape to France or Portugal. The Cortes were dissolved, and the federal and constituent Cortes of the republic convened, but they only sat during the summer of 1873, long enough to show their absolute incapacity, and to convince the executive that the safest policy was to suspend the session for several months.
This was the darkest period of the annals of the Spanish revolution of 1873–1874. Matters got to such a climax of disorder, disturbance and confusion from the highest to the lowest strata of Spanish society, that the president of the executive, Figueras, deserted his post and fled the country. Pi y Margall and Salmeron, in successive attempts to govern, found no support in the really important and influential elements of Spanish society. Salmeron had even to appeal to such well-known reactionary generals as Pavia, Sanchez, Bregna, and Moriones, to assume the command of the armies in the south and in the north of Spain. Fortunately these officers responded to the call of the executive. In less than five weeks a few thousand men properly handled sufficed to quell the cantonal risings in Cordoba, Seville, Cadiz and Málaga, and the whole of the south might have been soon pacified, if the federal republican ministers had not once more given way to the pressure of the majority of the Cortes, composed of Intransigentes and radical republicans. The president, Salmeron, after showing much indecision, resigned, but not until he had recalled the general in command in Andalusia, Pavia. This resignation was not an unfortunate event for the country, as the federal Cortes not only made Castelar chief of the executive, though his partisans were in a minority in the Parliament, but they gave him much liberty to act, as they decided to suspend the sittings of the house until 2 January 1874. This was the turning-point of the Spanish revolution, as from that day the tide set in towards the successive developments that led to the restoration of the Bourbons.
At the end of 1873 Castelar had reason to be satisfied with the results of his efforts, with the military operations in the peninsula, with the assistance he was getting from the middle classes and even from many of the political elements of the Spanish revolution that were not republican. On the other hand, on the eve of the meeting of the federal Cortes, he could indulge in no illusions as to what he had to expect from the bulk of the republicans, who openly dissented from his conservative and conciliatory policy, and announced that they would reverse it on the very day the Cortes met. Warnings came in plenty, and no less a personage than the man he had made captain-general of Madrid, General Pavia, suggested that, if a conflict arose between Castelar and the majority of the Cortes, not only the garrison of Madrid and its chief, but all the armies in the field and their generals, were disposed to stand by the president. Castelar knew too well what such offers meant in the classic land of pronunciamientos, and he refused so flatly that Pavia did not renew his advice. The Cortes met on 2 January 1874. The intransigent majority refused to listen to a last eloquent appeal that Castelar made to their patriotism and common sense, and they passed a vote of censure. Castelar resigned. The Cortes went on wrangling for a day and night until, at daybreak on 3 January 1874, General Pavia forcibly ejected the deputies, closed and dissolved the Cortes, and called up Marshal Serrano to form a provisional government.
Castelar kept apart from active politics during the twelve months that Serrano acted as president of the republic. Another pronunciamiento finally put an end to it in the last week of December 1874, when Generals Campos at Sagunto, Jovellar at Valencia, Primo de Rivera at Madrid, and Laserna at Logrono, proclaimed Alphonso XII king of Spain. Castelar then went into voluntary exile for fifteen months, at the end of which he was elected deputy for Barcelona. He sat in all subsequent parliaments, and just a month before his death he was elected as representative of Murcia. During that period he became even more estranged from the majority of the republicans. Bitter experience had shown him that their federal doctrines and revolutionary methods could lead to nothing in harmony with the aspirations of the majority of Spaniards. He elected, to use his own words, to defend and to seek the realization of the substance of the program of the Spanish revolution of 1868 by evolution, and legal, peaceful means. Hence the contrast between his attitude from 1876 to 1886, during the reign of Alphonso, when he stood in the front rank of the opposition, to defend the reforms of that revolution against Señor Canovas, and his attitude from 1886 to 1891. In this latter period Castelar acted as a sort of independent auxiliary of Sagasta and of the Liberal party. As soon as Castelar saw universal suffrage re-established he solemnly declared in the Cortes that his task was accomplished, his political mission at an end, and that he proposed to devote the remainder of his life to those literary, historical, philosophical, and economic studies which he had never neglected even in the busiest days of his political career. Indeed, it was his extraordinary activity and power of assimilation in such directions that allowed him to keep his fellow-countrymen so well informed of what was going on in the outer world.
His literary and journalistic labors occupied much of his time, and were his chief means of subsistence. He left unfinished a history of Europe in the 19th century. The most conspicuous of his earlier works were: A History of Civilization in the First Five Centuries of Christianity, Recollections of Italy, Life of Lord Byron, The History of the Republican Movement in Europe, The Redemption of Slaves, The Religious Revolution, Historical Essays on the Middle Ages, The Eastern Question, Fra Filippo Lippi, History of the Discovery of America, and some historical novels. Castelar died near Murcia on 25 May 1899, at the age of sixty-six. His funeral at Madrid was an imposing demonstration of the sympathy and respect of all classes and parties.