Who was the longest-reigning pope in history?

Pius IX, who led the Catholic Church for nearly 32 years, from 1846 to 1878, was the longest-reigning pope.

It was during his reign that the First Vatican Council, in 1870, promulgated the dogma of papal infallibility.

That doctrine states that the pope cannot err on matters of faith or morals when speaking ex cathedra, that is, in his official character of supreme pontiff.