Later, from 1981 to 2005, Cardinal Ratzinger was head of the Congregation for the Doctrine of the Faith. He was elected pope in 2005.