FLORHAM PARK, N.J. — Rex Ryan’s reinvention tour has come to an abrupt end.

Just five days before he was set to face his former team, he was relieved of his coaching duties on Tuesday by the Buffalo Bills.

The organization announced the decision in a statement.

“I spoke with Rex earlier today and we mutually agreed that the time to part ways is now,” said Bills owner Terry Pegula, who also fired Ryan’s twin brother Rob as assistant head coach/defense. “These decisions are never easy. I want to take this opportunity to thank Rex for all his efforts and wish him all the best moving forward.”

Offensive coordinator Anthony Lynn — the Jets running backs coach during Ryan’s tenure — will serve as interim head coach in Sunday’s season finale against the Jets at MetLife Stadium. ESPN also reported that the Bills are making the “business decision” to bench quarterback Tyrod Taylor to avoid paying him a guaranteed $30.75 million still left on his contact in the event that he gets seriously hurt in the game. Backup EJ Manuel is expected to start instead.

The Bills made a splash in January 2015 when they gave Ryan a five-year, $27.5-million contract just two weeks after he was dismissed by Jets owner Woody Johnson. In his introductory news conference last year, Ryan boasted about building “a bully” in Buffalo. But after going 15-16 in two seasons, he’s out of a job again.

advertisement | advertise on newsday

Last year, Ryan told reporters that Buffalo “is my last stop in coaching, and then when my days are up, I’ll turn it over to the younger generation. I’m not going anywhere else.”

Management’s patience with him grew thin after he was unable to make good on his lofty promises. The Bills finished 8-8 in 2015 and are currently 7-8. They haven’t made the playoffs in 17 years, the NFL’s longest active postseason drought.

NFL.com reported that Ryan felt his firing was “inevitable” and preferred to be let go now as opposed to waiting a week.

Bills defensive lineman Leger Douzable, who played for Ryan with the Jets, took to Twitter to vent his frustration. “We let Rex down as players,” he tweeted. “I’m tired of people talking about the 17 year drought. REX was here for 2 of those years hard to build a winner if the coach changes every two years.”

Despite Ryan’s reputation as a defensive mastermind, it was that unit that was most disappointing this season. The Bills, who fired defensive line coach Karl Dunbar (another former Jets assistant) in March 2016, are 19th in total defense, 15th in points allowed and have recorded 21 sacks, a franchise low for a 16-game season.

Including his six seasons with the Jets, Ryan has a 61-66 regular-season record. But he took issue with being labeled an average head coach, telling reporters at his introductory news conference in Buffalo: “I think they realize that I’m not a mediocre coach . . . I’m not a mediocre coach and anybody that thinks so, I would challenge them with that.”

Ryan’s larger-than-life personality and his reputation as a player’s coach made him a fan favorite early in his Jets career. His loyalty to his players also carried weight in the locker room.

Jets defensive end Sheldon Richardson, who was drafted by Ryan and former general manager John Idzik, said he “most definitely” thinks Ryan should coach again. “But that’s totally up to him,” he said. “Life twists and turns and takes you different places. You never know, he might coach again.”

Asked if it’s unfair for head coaches to be fired after two seasons, Richardson said: “That’s the business. I’m used to it, honestly.”