Ayala lived through the Primo de Rivera dictatorship, defended the Spanish republic that was declared in 1931 and spent decades in exile as a result of the fascist regime that followed. He once declared: "I bear no ill-will against anyone over my exile. What I do resent is the human condition, sometimes seen at its very worst – but that, you can find anywhere." This outlook pervaded his writings. He portrayed an essential goodness in humanity that was easily dislodged in times of crisis, when people will readily exploit and oppress others. His collection Los usurpadores (The Usurpers, 1949) reflects his view of the exercise of power as trespass against one's fellow humans.
Ayala was born in Granada to a petit-bourgeois, liberal family. His mother was a talented artist, his father a cultured but unsuccessful businessman. As a child, he read everything within reach, from comics to Don Quixote. He was 16 when his family moved to Madrid, where he later studied law. His literary debut, Tragicomedia de un hombre sin espíritu (Tragicomedy of a Man Without Spirit, 1925) was followed by Historia de un amanecer (A Dawn Story, 1926). They were minor novels in a dated style, but he was soon caught up in the set of avant-garde writers known as the Generation of 1927. By his graduation in 1929, he was in the circle around José Ortega y Gasset's cultural publication Revista de Occidente. El boxeador y un ángel (The Boxer and the Angel, 1929) and Cazador en el alba (The Huntsman at Daybreak, 1930) showed his vanguard credentials while Indagación del cinema (Explorations in Cinema, 1929) pioneered film criticism.
A postgraduate grant took Ayala to Berlin to study philosophy and sociology. There, he met the Chilean Etelvina Silva Vargas, whom he married in 1931. After collecting his doctorate in Madrid, he became a parliamentary clerk and a lecturer on civil rights and social legislation. In 1936, he was lecturing in South America when Franco rebelled, and hastened home to serve the republic in a variety of offices, including a diplomatic mission to Prague.
His younger brother Rafael was shot for desertion, his father jailed and summarily executed. The writer later admitted that he would have been prepared to shoot his wife, daughter and himself rather than be captured. As Franco's troops closed on Barcelona, Ayala escaped to Latin America.
In Argentina he returned to fiction, addressing moral and political themes. In El hechizado (The Bewitched, 1944), Los usurpadores and La cabeza del cordero (The Lamb's Head, 1949), Ayala established his mature voice. The latter stories, dealing with war as experienced intimately, achieved a more humane and universal reading of the Spanish conflict than other writers (André Malraux, George Orwell) who dwelt on its political and military dimensions.
He taught sociology, engaged in journalism and translation (including Rilke and Thomas Mann) and, in Buenos Aires, produced his Tratado de sociología (A Treatise on Sociology, 1947). In 1950, Ayala travelled to Puerto Rico to found a magazine and publish further in social and cultural studies.
In 1956 he moved to the US, where he taught Hispanic literature and finished his best-known novels, Muertes de perro (Death As a Way of Life, 1958) and El fondo del vaso (The Bottom of the Glass, 1962). Like Historias de macacos (Monkey Stories, 1955), these dark tales savagely satirised tyranny.
When Ayala first returned to Spain, in 1960, he described it as "a kind of pilgrimage" to an unknown homeland. Some outstanding intellectuals of the era, including the future Nobel laureates Vicente Aleixandre and Camilo José Cela, later published a welcome-home message. Ayala was grateful; little of his work had surfaced under Francoist censorship. Like other literary exiles of 1939, his name was on university curricula across the Atlantic long before it won fame in Spain.
In New York, the widowed Ayala met Carolyn Richmond, an expert on the Spanish novelist Leopoldo Alas, and then on Ayala himself, many of whose works she edited or translated. She became his second wife in 1999.
His definitive homecoming awaited Franco's demise. Meanwhile, alongside his own works of fiction, he published extensively on classical and contemporary literature. By 1972, his genius was acknowledged in Spain, when he won the Critics' Prize for the trilogy El jardín de las delicias (The Garden of Delights, 1971). The post-Franco transition to a vibrant, democratic culture came from "exhaustion from the effort of having done without for so long", he said.
Having retired in 1977 from his university career, Ayala settled in Madrid in 1980. Three years later, he won the National Prize for Narrative with his two-volume memoir Recuerdos y olvidos (Memories and Things Forgotten, 1982-83) and was elected to the governing authority of the Spanish language, the Real Academia Española (RAE), devoting his inaugural lecture to the rhetoric of journalism. Well into his 90s, he turned up for weekly meetings of the RAE.
Ayala won Spanish literature's highest honour, the Miguel de Cervantes prize, in 1991, years ahead of the already Nobel-garlanded Cela, and was himself a perennial candidate for the Nobel from 1996. He was awarded the National Prize in Spanish Letters in 1988 and the Prince of Asturias literary prize in 1998, but professed a disdain for honours. However, the Cervantes prize had a special meaning for him. The spirit of Cervantes, he said, had been present in everything he wrote since struggling through Don Quixote at the age of eight.
To mark the fourth centenary of Cervantes's masterpiece, Ayala published in 2005 La invención del Quijote (The Invention of Don Quixote), representing 65 years of his writings on Cervantes. The RAE's anniversary edition of Don Quixote, running to 1m copies, features Ayala's preface. Granada's Ayala Foundation, created by Andalusian universities and local authorities, hosted a symposium in 2004, exploring Ayala's relationship with the Americas, and sponsored the filming of some of his stories. In 2005, he travelled with Crown Prince Felipe to open the Ayala library in the Instituto Cervantes, Stockholm.
Ayala launched his own website on his 95th birthday, claiming to be so familiar with computers that he had forgotten how to write by hand. Accepting the invitation to his centenary conference, he said: "They seem determined that I should keep on having birthdays... I wouldn't want to spoil the show."
He is survived by Carolyn and his daughter, the art historian Nina Ayala Mallory, from his first marriage.
- Francisco de Paula Ayala García-Duarte, writer, born 16 March 1906; died 3 November 2009