CINCINNATI -- In a surprising turn of events for a franchise that seemed destined to part ways with its longtime head coach, the Bengals signed Marvin Lewis to a two-year deal through the 2019 season, it was announced Tuesday.

Lewis' return comes after days of discussions with Bengals owner Mike Brown. On Monday, Lewis repeatedly said the talks were all about "getting on the same page," but did not elaborate as to what that meant.

"Marvin Lewis has been an important member of the Cincinnati community and the Bengals family for the past 15 years, and we are happy to have reached this agreement," Brown said in a statement. "Marvin has made significant contributions during his time here. While recently we have fallen short of our expectations, we have full confidence in Marvin to re-establish winning football in 2018."

The Bengals wrapped up a 7-9 season Sunday with a 31-27 victory over Baltimore.

Lewis is the NFL's second-longest-tenured coach, behind only the New England Patriots' Bill Belichick. Lewis is coming off two disappointing seasons and has no playoff wins during his 15 years with the team -- the longest tenure in franchise history -- despite seven trips to the postseason.

"My family and I are very grateful for the opportunity to stay in Cincinnati and continue my career with the Bengals," Lewis said in a statement. "My job is to win a World Championship. We have a talented roster full of veteran leaders and emerging young stars, and I am committed to making the necessary improvements to put this team in the best position to win."

Marvin Lewis is the Bengals' all-time leader in coaching wins, losses and postseason appearances, but has zero wins in seven playoff games. Ian Johnson/Icon Sportswire

ESPN reported last month that Lewis planned to leave after the season. But Lewis always planned a postseason sit-down with owner Mike Brown, and sources say Brown was able to address Lewis' concerns enough to convince the coach to sign on for two more years. Coaches and people in the organization, expecting Lewis to leave, were surprised and pleased to learn he would be staying, according to sources.

Lewis, 59, may have been seeking more control over changes in the staff and the ability to be more aggressive in free agency. The Bengals value continuity and rarely make staffing changes. Some of the assistants, including offensive line coach Paul Alexander, have been with the franchise since before Lewis arrived or since his first season.

Defensive coordinator Paul Guenther, a potential candidate to replace Lewis had the team changed head coaches, will leave the organization to pursue opportunities elsewhere, a source told ESPN.

Guenther has an expiring contract, and he is expected to be a leading candidate to become defensive coordinator with the Oakland Raiders when Jon Gruden takes that job, a source told ESPN's Adam Schefter.

On Wednesday, the Bengals announced that offensive coordinator Bill Lazor had been signed to a new contract. This season was Lazor's first as the offensive coordinator after being promoted to the position in September when the Bengals fired Ken Zampese.

CINCINNATI BENGALS 2018 draft position: Top-10 selection in first round and seven overall picks (could possibly get up to three compensatory picks). 2018 salary cap space: $35.1 million 2018 starting QB: Andy Dalton. He struggled along with the rest of the Bengals' offense in 2017, and the unit plummeted to last in yards per game. The Bengals could get out of Dalton's contract next year with $2.4 million in dead money. But, considering how much the franchise values continuity and has stood behind its veterans, it would be surprising if Cincinnati moved on from Dalton. Key free agents: LB Kevin Minter, TE Tyler Eifert Bill Barnwell's job grade: C+ -- Katherine Terrell

The Bengals rarely pursue big names in free agency and prefer to build through the draft. They have also lost some of their best players to other teams, including Andrew Whitworth, Kevin Zeitler and Marvin Jones, all of whom would have likely helped their last-place offense.

Although the 11th-hour return is surprising, there is a precedent for it. Lewis last went into the final year of a contract in 2010, but he ended up returning. Lewis and Brown had not come to an agreement prior to that season, partially because Lewis was seeking some concessions from Brown, including more control of personnel. Lewis and Brown decided to move forward together after two days of discussions following a 4-12 finish that season.

The Bengals began their run of success after that, drafting quarterback Andy Dalton and wide receiver A.J. Green and making a run of five straight playoff berths.

Lewis helped rebuild a Bengals franchise that was considered an NFL's laughingstock when he accepted the job in 2003. The Bengals have won four AFC North titles under Lewis.

He has posted a 125-112-3 record in his 15 seasons and is the Bengals' all-time leader in wins, losses and postseason appearances. He is the only coach in NFL history to lose his first seven postseason games, according to the Elias Sports Bureau.