HOLY SCHISM! Pope Gregory XII was the last pontiff to resign, following a 40-year war within the Catholic Church, in 1415. Photo: Getty Images

(
)

The last time a pope resigned, his health was fine — but his church was falling apart.

Nearly six centuries before Pope Benedict XVI stunned the world with news that he is too old and frail to continue as leader of the Roman Catholic Church, Pope Gregory XII agreed to step down in a bid to heal the badly fractured religious institution.

Cutting a deal with church leaders in 1415, Gregory XII resigned his 10-year post to end a Catholic civil war that had raged for nearly 40 years.

The warring factions — some of which had elected their own “popes” — were then reunited under one new pontiff, Martin V.

The move effectively ended what was known as the Western Schism.

Before his resignation, Gregory XII and Rome had been in a standoff with two so-called “antipopes” — Benedict XIII in Avignon, France, and John XXIII in Pisa, Italy — over who held the legitimate claim to leadership of the church.

Gregory XII was the successor to a line of popes under Pope Urban VI to lead the church from Rome, after having run things from Avignon from 1309 to 1378.

But local church officials in Avignon balked at the move. In 1378, they elected their own pope, Clement VII, who was succeeded by Benedict XIII.

For years, Gregory XII and Benedict XIII ruled the two separate papal courts.

Then, in 1409, a council met in Pisa, hoping to end the fractured leadership. Instead, it aggravated everything by electing a third pope.

With three popes now making claims of legitimacy — each appointing cardinals, courting foreign diplomats and claiming to be able to canonize saints — a call went out for another meeting.

Pope Gregory helped assemble the powwow, called the Council of Congress. He agreed to resign, and the other two “popes’’ were eventually ousted in favor of Gregory’s successor, Martin V.

In 1045, Pope Benedict IX, whose scandalous tenure reportedly included orgies, resigned after being paid off by his successor, Pope Gregory VI.

The next year, Gregory VI was forced to resign.

In 1294, reclusive Pope Celestine V issued the first official decree allowing popes to step down — and promptly did so himself.

Earlier, in 1009, Pope John XVIII resigned and retired to a monastery, and in 303, Pope Marcellinus was forced out after caving to the decree of Roman Emperor Diocletian to worship false idols. He later repented and became a martyr.

The first pope known to have resigned was St. Pontian, who was elected in 230 and exiled to the Sardinian salt mines in 235.