After the Popular Front victory, Miaja was appointed commander of the 1st Division in Madrid. On the outbreak of the Spanish Civil War he remained loyal to the Republic and accepted the post of minister of war under Diego Martinez Barrio. However, he resigned from the post when José Giral was appointed prime minister.
Miaja now became commander of the 3rd Division in Valencia but failed to capture Cordoba from the Nationalist Army in August 1936. Two months later he once again became commander of the 1st Division in Madrid.
Francisco Largo Caballero and his government decided to leave the capital on 6th November, 1936. This decision was criticized by the four anarchists in his cabinet who regarded leaving the capital as cowardice. At first they refused to go but were eventually persuaded to move to Valencia with the rest of the government.
Before he left, Largo Caballero appointed Miaja as commander of the Republican Army in Madrid. He was given instructions to set up a Junta de Defensa (Defence Council), made up of all the parties of the Popular Front, and to defend Madrid "at all costs". He was aided in this task by his chief of staff, Vicente Rojo.
Soon after taking command of Madrid Miaja surprisingly joined the Communist Party (PCE). Over the coming months the PCE obtained more and more power in the capital. This was especially a concern to other left-wing groups such as the Worker's Party (POUM) and the National Confederation of Trabajo (CNT).
Miaja's task of defending the capital was helped by the arrival of the International Brigades. The first units reached Madrid on 8th November. Led by the Soviet General, Emilo Kléber, the 11th International Brigade was to play an important role in the defence of the city. The Thaelmann Battalion, a volunteer unit that mainly consisted of members of the German Communist Party and the British Communist Party, was also deployed to defend the city.
On 14th November Buenaventura Durruti arrived in Madrid from Aragón with his Anarchist Brigade. Six days later Durruti was killed while fighting on the outskirts of the city. Durruti's supporters in the CNT claimed that he had been murdered by members of the Communist Party (PCE).
Santiago Carrillo, the Councillor for Public Order in the Defence Council, argued that the main reason that the Nationalist forces was attempting to capture Madrid was the desire to release the large number of Nationalist Army officers in Madrid's prisons. Carrillo was given permission to take them out of the city by bus.
An estimated 2,000 Nationalist soldiers were murdered at Paracuellos del Jarama and Torrejón de Ardoz. Communists later claimed that the buses were hijacked by Anarchists and they were responsible for the killings. However, no evidence has emerged to support this claim. In fact, after the war Francisco Franco claimed that Carrillo and his Communists were guilty of killing 12,000 Nationalists in Madrid.
On 13th December 1936, the Nationalists attempted to cut the Madrid-La Coruna road to the north-east of Madrid. After suffering heavy losses the offensive was brought to an end over Christmas. On 5th January 1937, the attack was resumed. During the next four days the Nationalist gained ten kilometres of road and lost around 15,000 men. The International Brigades, defending the road, also suffered heavy losses during this battle.
General Francisco Franco came under pressure from Adolf Hitler and Benito Mussolini to obtain a quick victory by taking Madrid. He eventually decided to use 30,000 Italians and 20,000 legionnaires to attack Guadalajara, forty miles northeast of the capital. On 8th March 1937 the Italian Corps took Guadalajara and began moving rapidly towards Madrid. Four days later the Republican Army with Soviet tanks counter-attacked. The Italians suffered heavy losses and those left alive were forced to retreat on 17th March.
In April 1938 Miaja was made commander of all military forces in central and southern Spain. However, he became increasingly concerned about the ability of the Republican Army to win the war. When Juan Negrin refused to negotiate a peace agreement with the Nationalists, Segismundo Casado, commander of the Republican Army of the Centre, Cipriano Mera, commander of the 4th Army Corps, and Julián Besteiro of the Socialist Party, established an anti-Negrin National Defence Junta.
On 6th March 1938, Miaja joined the rebellion by ordering the arrests of Communists in Madrid. Negrin, about to leave for France, ordered Luis Barceló, commander of the First Corps of the Army of the Centre, to try and regain control of the capital. His troops entered Madrid and there was fierce fighting for several days in the city until Mera's troops managed to defeat the First Corps.
Segismundo Casado now tried to negotiate a peace settlement with General Francisco Franco. However, he refused demanding an unconditional surrender. Members of the Republican Army still left alive, were no longer willing to fight and the Nationalist Army entered Madrid virtually unopposed on 27th March.
Miaja fled to Valencia and subsequently emigrated to Mexico. José Miaja died in 1958.