McDermott, 42, was one of four coaches to interview for the Bills' vacancy, along with interim coach Anthony Lynn, Arizona Cardinals offensive coordinator Harold Goodwin and Seattle Seahawks defensive coordinator Kris Richard.
McDermott had interviewed for a second time with Buffalo ownership on Wednesday in Boca Raton, Florida.
"We believe we have hired a smart, determined and hard-working head coach who has been training for many years to achieve this goal," Bills co-owner Terry Pegula said in a statement. "Sean is an ambitious leader who has the desire to lead this organization to compete for and ultimately win a Super Bowl. We look forward to working with Sean for many years to come."
It remains unclear how much control McDermott will have over the Bills' roster and personnel decisions. General manager Doug Whaley had final say over the 53-man roster during Ryan's two-year tenure, though sources told ESPN NFL Insider Adam Schefter earlier this month that the Bills were planning on giving their new coach more power within the organization. Both Whaley and Ryan reported directly to Pegula.
In recent days, sources said McDermott had received encouraging answers to his questions about the team's front-office structure and how it would work day-to-day if he took the job. McDermott is not seeking "control," sources said, as much as he is seeking specifics about who is responsible for what and how they'll all work together.
"I am very appreciative of the opportunity to become the Buffalo Bills' new head coach and join the rich tradition of Bills football," McDermott said in a statement. "I am looking forward to connecting with our players, Bills staff and the passionate fan base. I want to thank Terry and Kim, and I look forward to working with Doug and the entire football department."
Pegula and his wife, co-owner Kim Pegula, tapped Whaley to lead the coaching search after Ryan was fired Dec. 27. Whaley, who will enter his fifth season as Bills general manager in 2017, said he was part of a "committee approach" that included team president Russ Brandon when Ryan was hired in 2015.
McDermott will become the 20th coach in the Bills' 57-year history. The team's previous eight coaches, including interim coaches Perry Fewell (2009) and Lynn (2016), all posted losing records and failed to make the playoffs. The Bills have not made the postseason since 1999 under Wade Phillips, a 17-year drought that is the longest active streak in the NFL and is tied for the fifth-longest playoff drought in NFL history.
McDermott spent the past six seasons leading the Panthers' defense, after two seasons (2009-10) as the Philadelphia Eagles' defensive coordinator. A graduate of William & Mary, McDermott joined the Eagles' scouting department in 1999 and progressed into coaching the team's defensive backs.
McDermott's likely defensive coordinator in Buffalo will be Panthers linebackers coach Al Holcomb, a source told ESPN's Schefter.
The Panthers' defense ranked 21st in yards allowed this season and 26th in points allowed. However, Carolina's defense finished in the top 10 in yards allowed in each season from 2012 to 2015.
"His résumé should speak for itself," Panthers coach Ron Rivera said last month of McDermott. "Sometimes when you hire people, you need to look at not whether or not they're the hot guy but what they've done consistently over a period of time."
McDermott is expected to bring a 4-3 defensive scheme back to the Bills, who finished fourth in yards allowed in 2014 while using former defensive coordinator Jim Schwartz's 4-3 system.
The Bills used a multiple scheme with more 3-4 principles under Ryan the past two seasons, ranking 19th in yards allowed both years. Some defensive players voiced their concerns before and after Ryan's firing about the complexity of his defense as compared to Schwartz's more straightforward approach.
Whomever McDermott hires as offensive coordinator must deal with the potential loss of quarterback Tyrod Taylor. The Bills could decide to release Taylor -- whose passing statistics were down this season from their 2015 levels -- before $30 million of his contract becomes guaranteed on March 12.
Buffalo finished 7-9 this season. In 31 games as Bills coach, Ryan had a 15-16 record.
CBS Sports and ESPN's Dan Graziano earlier reported news of McDermott's hiring.