A pitcher who barely held off Ivan Nova for the Yankees’ fifth starter job in spring training ended up throwing the second-most innings for the club in 2016 and finished with a sub-4.00 ERA.

Few would have predicted that kind of year for CC Sabathia.

Except, of course, the veteran lefthander, who throughout the spring, even when he struggled, said “If I’m healthy,” the production would be there.

And for the most part it was.

Sabathia, after three straight subpar seasons, went 9-12 this year but with a 3.91 ERA. He completed the year without a shoulder injury, triggering the final year of his contract to vest for $25 million.

In his final start Thursday night against the Red Sox, who led the majors in runs scored, the 36-year-old allowed one run and four hits in 7 1/3 innings of a 5-1 Yankees victory.

advertisement | advertise on newsday

The outing allowed Sabathia to go 2-2 with a 2.37 ERA in his last eight starts.

“It was good,” Sabathia said of his season. “I was able to make it through healthy, make 30 starts. Just looking to do the same thing next year and just get better.”

Sabathia’s 30 starts were the most he’s made in a season since making 32 in 2013, a season he went 14-13 but with a 4.78 ERA.

That came after a 2012 in which he went 15-6 with a 3.38 ERA. The 2013 season started a three-season slide in which Sabathia, struggling in his transition from power pitcher to one with a fastball mostly resting in the 88-90 mph range, combined to go 23-27 with a 4.81 ERA.

“He had to reinvent himself,” one opposing team scout said. “And he did.”

Yankees videos

Armed with an improved cutter, one former Yankee and close friend Andy Pettitte worked with him on two springs ago, Sabathia threw 179 2/3 innings, second on the club behind Masahiro Tanaka’s 199 2/3.

“I think it did a lot,” manager Joe Girardi said of Sabathia’s cutter. “It helped him get a lot of outs; induce weak contact at times, strikeouts at times with it. The ability to be able to pitch for the most part a lot less pain free was a big deal for him.”

Pain in a troublesome left knee contributed to Sabathia’s difficulties from 2013-15 more than anything.

But he started using a lightweight brace at the end of 2015 — Sabathia had a 2.17 ERA in his last five outings of that season — which he believes helped stabilize the knee.

“It’s been a long time since I’ve been able to pitch through a season,” said Sabathia, who missed only two starts because of a sore right ankle. “It feels good.”

advertisement | advertise on newsday

Uncertainty surrounds the Yankees’ rotation for next season as Tanaka, Sabathia and Michael Pineda are the only three pitchers all but assured of being in it.

Young pitchers like Luis Cessa, Chad Green, Bryan Mitchell and Luis Severino are also expected to compete for spots.

Still, that Sabathia is in a position of having his spot virtually locked in for 2017 isn’t something many would have predicted a year ago.

Just don’t tell Sabathia it’s a surprise.

“For me,” he said, “it was just about staying healthy.”