He was born in Alcal de Henares, near Madrid, the son of a poor medical practitioner. In 1569 he published his first known work, a collection of pieces on the death of the queen. He then travelled to Italy in the service of Cardinal Giulio Acquaviva, and enlisted as a soldier. After service against the Turks in Tunis, he was returning to Spain in 1575 when the galley he sailed in was captured by Algerian corsairs, and with his brother Rodrigo and others he was carried into Algiers, where he remained in captivity for five years, during which he made four daring attempts to escape. In 1580 he was ransomed by the efforts of Trinitarian monks, Algiers traders and his family. Finding no permanent occupation at home, he drifted to Madrid, and tried a literary career. In 1584 he married Catalina de Salazar y Palacios (1565-1626). The marriage was childless, but Cervantes had an illegitimate daughter, Isabel de Saavedra (c.1585-1652).
His first important work was the pastoral romance La Galatea (1585, Eng trans 1867). For some years he strove to gain a livelihood by writing plays, La Numancia (1584, Eng trans 1870) and El trato de Argel (1598, Eng trans The Commerce of Algiers, 1870), have survived.
In 1594 he was appointed collector of revenues for the kingdom of Granada, but in 1597, failing to make up the sum due to the treasury, he was sent to prison in Seville, released after three months, but not reinstated. Local tradition maintains that he wrote Don Quixote, the first part of which came out in Madrid in early 1605, in prison at Argamasilla in La Mancha. It was immediately popular, though Lope de Vega dismissed it, but instead of giving his readers the sequel they asked for, Cervantes busied himself with writing for the stage and composing short tales, published as Novelas Ejemplares (1613, Eng trans Exemplary Novels, 1972). His Viage al Parnaso (1614), a poem of over 3,000 lines in terza rima, reviews the poetry and poets of the day.
In 1614 a pseudonymous writer brought out a spurious second part of Don Quixote, with an insulting preface, which spurred Cervantes to the completion of the genuine second part (1615). While it was in the press he revised his various plays and interludes, and a little before his death, he finished the romance of Persiles y Sigismunda (1617, Eng trans The Travels of Persiles and Sigismunda, 1619).
Though it is the most carelessly written of all great books, Don Quixote is widely regarded as one of the best books in the world, and seen as the precursor of the modern novel, as well as a great comic epic in its own right.