Sancho the Pious (1209 - 1248) became king in 1223. He was good at military decisions, but not an efficient administrator, nor did he do anything to mediate disputes between the middle class and the church. Strife in Portugal became so bad that the archbishop appealed to the pope. Between papal disapproval and the Portuguese nobles disliking Sancho's style, he had to go. He was deposed in December 1247—officially ordered out by Pope Innocent IV—and died one month later.
Afonso was summoned from Boulogne, and had to give up his right to the position there in 1248. Besides the position of Count, he gave up the Countess: he divorced Matilda in 1253 and married Beatrice of Castile.
Avoiding the mistakes of his brother, Afonso III of Portugal paid close attention to the needs of the people. He created the Cortes, a parliament that included the nobility, clergy, and the bourgeoisie. He created laws preventing the aristocracy from exploiting the lower classes. He ensured that arrests had to be presented to a judge to determine the type and length of detention. Unfortunately, taxation of the Church may have been the step that led to his excommunication. The throne then went to his son, Denis, who was only 18 years old.