BUFFALO, N.Y. (AP) -- A person familiar with discussions tells The Associated Press that Rex Ryan has agreed to coach the Buffalo Bills.

Rex Ryan, is greeted by Clemson supporters on the field after the Russell Athletic Bowl NCAA college football game against Oklahoma in Orlando (AP Photo/John Raoux)

The person said the agreement was reached Sunday after the Bills extended the offer to the former New York Jets coach and he accepted. The person spoke on the condition of anonymity because the Bills have not announced the decision.

The agreement comes a day after Ryan had a second interview with the team in South Florida, where Bills new owners Terry and Kim Pegula live.

Ryan is staying in the AFC East, and will replace Doug Marrone, who abruptly opted out of the rest of his contract on Dec. 31.

Ryan was one of 12 candidates to interview for the job since last weekend.

At the same time, the Bills are negotiating to hire Greg Roman as their offensive coordinator, the person said. Roman, a finalist for the Bills' coaching job, spent the past four years as the San Francisco 49ers' offensive coordinator. Roman's future is uncertain in San Francisco after coach Jim Harbaugh left to coach Michigan.

This is the Bills' sixth coaching search since Wade Phillips was fired after the 2000 season and the first since Terry and Kim Pegula bought the team from the estate of Hall of Fame owner Ralph Wilson in October. The Pegulas were involved in all the interviews, many of them done at their South Florida home.

The Bills went 9-7 to match their best record in a decade, but missed the playoffs to extend the NFL's longest active drought to 15 seasons.

Ryan is very familiar with the Bills after spending the past six seasons coaching their AFC East rival. He had a 50-52 record, including 4-2 in the playoffs, with the Jets before being fired along with general manager John Idzik following a 4-12 finish.

Ryan's father, Buddy, also had ties to Buffalo after spending 1961-65 as an assistant coach at the University at Buffalo.

Ryan's strength is defense, as it is with the Bills. Buffalo's defense finished fourth in the NFL in yards allowed last season and produced three Pro Bowl linemen.

It's unclear how Ryan's arrival would affect the status of Buffalo's current defensive coordinator Jim Schwartz, who completed his first season with the Bills. Schwartz is the former Detroit Lions coach and was a candidate for the Bills job.

Ryan's challenge in Buffalo would be similar to the one he had in New York — providing a spark to a sputtering offense. The Jets finished 22nd in yardage last season — four spots ahead of Buffalo.

Quarterbacks were concerns for both teams, involving two players drafted in 2013 draft.

The Jets faltered behind second-year starter Geno Smith, who was eventually benched and replaced by Michael Vick. In Buffalo, second-year starter EJ Manuel was benched after four games and replaced by 10-year journeyman Kyle Orton, who has since said he plans to retire.

Manuel has two years left on his contract and is the only experienced starter on the Bills roster.

Roman is regarded as a good fit under Ryan, because the two share a similar run-first philosophy. Under Roman, the 49ers' running attack ranked among the NFL's top 10 in each of the past four seasons.

He and the Pegulas also share Penn State ties. Pegula attended Penn State and is a major supporter of its football and hockey programs. Roman was a candidate to become the school's football coach in each of its last two vacancies.

(Copyright 2015 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.)