Papal primacy and papal infallibility were decreed by a Church Council, the First Vatican Council (1869-1870):
So, then, if anyone says that the Roman Pontiff has merely an office of supervision and guidance, and not the full and supreme power of jurisdiction over the whole Church, and this not only in matters of faith and morals, but also in those which concern the discipline and government of the Church dispersed throughout the whole world; or that he has only the principal part, but not the absolute fullness, of this supreme power; or that this power of his is not ordinary and immediate both over all and each of the Churches and over all and each of the pastors and faithful: let him be anathema.
. . .
Therefore, faithfully adhering to the tradition received from the beginning of the Christian faith, to the glory of God our savior, for the exaltation of the Catholic religion and for the salvation of the Christian people, with the approval of the Sacred Council, we teach and define as a divinely revealed dogma that when the Roman Pontiff speaks EX CATHEDRA, that is, when, in the exercise of his office as shepherd and teacher of all Christians, in virtue of his supreme apostolic authority, he defines a doctrine concerning faith or morals to be held by the whole Church, he possesses, by the divine assistance promised to him in blessed Peter, that infallibility which the divine Redeemer willed his Church to enjoy in defining doctrine concerning faith or morals. Therefore, such definitions of the Roman Pontiff are of themselves, and not by the consent of the Church, irreformable.
So then, should anyone, which God forbid, have the temerity to reject this definition of ours: let him be anathema.