Alfonso I., the first king of Portugal, son of Henry of Burgundy, count of Portugal, died in 1185. He was several times at war with the kingdom of Castile; but on the establishment of peace he turned his arms against the common enemy, the Moors, and fought a battle in 1139, on the plains of Ourique, against the Moorish king of Badajoz and his allies, which completely broke the Moslem power in Portugal. After this victory he assumed the royal title. In 1146 he took the town of Santarem after an obstinate defence, and put to the sword every living soul; and the following year Portugal was free. He instituted a code of laws, still known as the laws of Alfonso. He was succeeded by his son Sancho I.