Because the Doctor was given a new regeneration cycle by the Time Lords at the end of the 2013 Christmas special The Time of the Doctor. It’s been known since the 20th anniversary special that the Time Lord High Council can grant new regeneration cycles to certain Time Lords, to circumvent the thirteen-life, twelve-regeneration limit. And they did that with the Doctor because they needed him to save them from the invaders appearing over the link to Gallifrey (basically, the Doctor prevented his archenemies the Daleks from killing off the Time Lords in the previous episode by moving Gallifrey into a pocket universe; the Time Lords wanted to return to our universe, so they created a link to a crack in space-time on the planet Trenzalore, the crack having been made by agents exploding the Doctor’s spaceship/time machine, or TARDIS, in an attempt to prevent him allowing the Time Lords’ return); if he died, that would be the end of the Time Lords. (Actually, there’s also a story in there involving the name of the Doctor, in which if he speaks his name through the crack, the Time Lords take it as a password to return to our universe. They have many enemies, hence the invaders over Trenzalore seeking to destroy the returning Gallifrey once and for all, and thus the agents being sent back in time to explode the TARDIS.)
https://www.quora.com/Why-can-The-Doctor-regenerate-more-than-12-times-Hes-had-13-lives-now-Peter-being-the-13th
The doctor was close to dying, in fact he was every old but as sated above he was gifted a new set of regeneration cycle.