In 1248 he collected a large army, and prepared to start by way of Sicily, the nearest route to Palestine, when he remembered that the island belonged to Frederick II., of Germany, who was under excommunication by the Pope. All attempts to shake the decision of Innocent IV. failed; and yielding to the pious weakness of fearing to rest in an excommunicant's territory, Louis changed his plans, and determined to pass by way of Cyprus and Egypt—a route which proved the ruin of the expedition. He committed the regency of France to his mother, assumed the staff of pilgrimage, and accompanied by his wife and brothers, left Paris on June 12, 1248. He stayed for several months in Cyprus, until his armament amounted to 50,000 men, and then sailed for Egypt.

Arrived at the port of Damietta, he caused the oriflamme (the national standard of France) to be waved above his head; and, arrayed in complete armor, he unsheathed his sword, and leaped into the sea, followed by the knights. The inhabitants fled, and the French took possession of the city. The inundation of the Nile prevented their further movements for several months. Licentiousness and disease were fostered by this delay, in spite of the king's remonstrances; and their unopposed success made the Crusaders careless as to the tactics of the enemy.

On the subsidence of the Nile, Louis fortified Damietta, and left his queen and her ladies there, while he, with the main army, advanced on Cairo, the metropolis of Egypt, where the sultan resided. Near Mansourah, the Crusaders became perplexed by the intricacy of the canals, and a hasty dash across one of these, made by the king's brother, the Count of Artois, with 2,000 men, led to a calamitous result. Mansourah was apparently deserted, and the count's troops, who preceded their comrades at some distance, commenced pillaging the houses. The inhabitants, who were only concealed, showered down stones from the roofs; and at the same moment, a large body of the sultan's army made an attack in front. Louis reached Mansourah in time to save a few of his men, but found his brother and several others slain. The Moslem camp was captured, but proved a doubtful prize. The plains were barren and scorching, and the harassing assaults of the Egyptians, who poured "Greek fire" (missiles filled with combustible materials) on their foes, rendered the situation more intolerable still. Pestilence broke out, and the king himself fell dangerously ill. He then ordered a retreat to Damietta, whither the sick were to be conveyed in galleys. These were intercepted, and the sick murdered by the Egyptians; while, at the same time an attack was made on the Christian camp.

Louis was so weak that he could scarcely ride, but nevertheless would not desert his post. He rode between the ranks, encouraging his men, till he fainted and was obliged to withdraw from the field. His quaint and affectionate biographer, the Lord of Joinville, who was with him in this expedition, thus describes the scenes which ensued: "Of all his men-at-arms there was only one with him, the good knight, Sir Geoffrey de Sargines; and who, I heard say, did defend him like as a faithful servant doth guard his master's cup from flies—for every time that the Saracens did approach the king he defended him with vigorous strokes of the blade and point of his sword, and his strength seemed doubled. At last he brought the king to a house where there was a woman from Paris; and laying him on the ground, placed his head on the woman's lap, expecting every moment that he would breathe his last." In this half-dying condition a body of Egyptians found him, and bore him to the tent of the sultan. The defeat of the Christians, who were weakened by the climate, disease, and want of food, was general; many fell by the sword, and the rest were taken prisoners with their king.

In captivity Louis showed a noble resignation and courage amid the apostasy of many. He won the respect of the sultan, who treated him with generosity, and listened to the terms of ransom which he proposed. The queen remained at Damietta, which was strongly garrisoned. Fearful, nevertheless, of falling into the hands of the Moslems, who would have carried her into the sultan's harem, she prayed an old knight in her suite to slay her with his sword, should there be any danger of that event. "I had determined on so doing, madam," was the answer. Margaret's heroism was not put to this severe test, for the surrender of Damietta was one of the conditions of her husband's release; and after paying in addition a sum of 400,000 livres, Louis was on the point of being set free. An insurrection, however, suddenly arose among the Mamelukes, or Tartarian troops, in whose hands the real power of the state was placed, and the sultan was murdered. A party of the assassins, it is said, entered the chamber of Louis with their scimitars drawn, but his calm dignity saved him, and the treaty was carried out by the new sultan.

Many of the French nobles returned home, but the king, faithful to his vow, proceeded to Syria, and spent four years in strengthening the fortresses of Tyre and other Christian towns, redeeming many Crusaders from slavery, and reducing to order the disturbed condition of the country.

The death of the Queen Dowager Blanche, who had governed France wisely during her regency, recalled him in 1254, after an absence of six years. He still wore the cross upon his shoulder, as a token that his oath as a Crusader was not yet fulfilled; but he never once neglected the more pressing and necessary duties which devolved on him as a monarch. His immediate work was to supersede the arbitrary legislation which the nobles exercised in their manorial courts over their tenants. He accordingly introduced into general use the famous code of Roman laws known as the Pandects of Justinian, and constituted the chief civil lawyers, who had studied its contents and were best acquainted with its principles, into a Parliament, or Court of Justice. The nobles and the clergy were duly represented in this assembly; but its clerks, or lawyers, were especially favored by the king, who seconded their own efforts to absorb the business of the court as much as possible. Louis further mediated between the tyranny of the nobles and the weakness of their tenants, by encouraging the practice of appealing to the crown in case of injustice. This he even extended to ecclesiastical matters; a bold step for one so devoted to the Church. The prohibition of the barbarous custom of duelling to decide personal quarrels was another of his humane laws. These, and divers other ordinances, founded in a like spirit of equity, are known in a collected shape as the Institutes of St. Louis. His enactment touching appeals from the Church to the Crown, and the prohibition which he likewise issued against the levying of money in France for the use of the Pope without the king's license, are known as a Pragmatic Sanction—a term applied to any especially important national decree. Louis set the example of enforcing the laws personally, and none was fitter to administer them than he. Under an oak in the forest of Vincennes, near Paris, often sat the good king to hear appeals and petitions from his poor subjects. His social and foreign relations were as fully attended to as his political reforms. He first placed the French navy on a substantial footing. To him Paris owed a public library, a hospital for the blind, and the establishment of a body of police. Under his sanction, also, his confessor, Robert de Sorbon, founded the famous theological college called by his name. So scrupulously just and honorable was Louis, that he appointed a commission to ascertain what restitution of territory should be made to nations which had been mulcted by the conquests of his predecessors, and he thus more than once sacrificed extensive possessions for the sake of a principle. By a treaty in 1255, made with Henry III., Louis restored to the English crown the provinces of which Philip Augustus had deprived it, and obtained in return the surrender of Henry's rights in Normandy and other fiefs. The reputation which Louis thus acquired among his fellow-monarchs led to his being asked to act as mediator in several quarrels, and gave him many opportunities of exhibiting his peaceful and loving policy.