In the beginning of the 14th century, the legitimacy of the Roman papacy was contested, because of a political, rather than a theological dispute. Avignon became a second pontifical city with so-called antipopes, in 1309.
In 1376, Pope Gregory XI returned from Avignon to Rome. He died shortly after, in 1378. The cardinals elected the Italian Urban VI. A faction of the College of Cardinals disputed the election of Urban VI and elected Clement VII the same year, who settled in Avignon.
This meant the beginning of the Great Western Schism in the Roman Catholic Church (1378-1417). Pedro de Luna was elected pope by the cardinals supporting Avignon in 1394, with the understanding that he would abdicate voluntarily if that would help to end the division in the church.
This he later refused to do, when asked to resign by the French princes who had been among his supporters. Eighteen of his 23 cardinals deserted him, and the papal palace in Avignon was besieged by the French (1398).
In 1403 Benedict escaped from the palace to Provence, rallied his cardinals, and won back the obedience of France. In 1408, the French declared themselves neutral in the dispute.
In 1409, a number of cardinals tried to end the rift during the Council of Pisa, by pronouncing both reigning popes of the day, Gregory XII (Rome) and Benedict XIII (Avignon) deposed. They elected Alexander V in their stead. Both popes refused to abdicate, with the result that there were now three reigning popes who considered themselves as rightful popes: Gregory XII, Benedict XIII and Alexander V.
Benedict still possessed the allegiance of some states, but had to take refuge in the castle of Peñíscola in 1415. The same year, the Council of Constance pronounced Benedict deposed, and elected Martin V in 1417, who was generally accepted.
This officially ended the Great Western Schism.
Benedictus lost all governmental recognition, except that of Armagnac (France) and of Scotland.
But he refused to yield to Pope Martin V, and maintained to the end of his life that he was the rightful pope. He created four new cardinals as late as November 1422.
Thus, Peñíscola prides itself in being a pontifical city, alongside Rome and Avignon, when Benedictus XIII took up his residence there (1415-1423).
After the pontifical period, Peñíscola became one of the cities within the Kingdom of Valencia once again, the formation of which started with the conquests of Jaime El Conquistador in the 13th century.