The Dolphins are working on a deal with San Francisco 49ers offensive coordinator Mike McDaniel to make him their next head coach, sources told ESPN’s Adam Schefter.

When a deal is done it will mark the end of a nearly month-long search since the Dolphins fired Brian Flores on Jan. 10.

Dallas Cowboys offensive coordinator Kellen Moore was the other finalist for the job.

McDaniel will get his first head-coaching job at any level after spending 15 seasons in the NFL and two in the UFL. He spent one season as San Francisco’s offensive coordinator after being promoted in January 2021. In that season, the 49ers had the league’s seventh-best offense in terms of yards per game and produced an All-Pro in wide receiver Deebo Samuel.

McDaniel began his NFL career as an intern for the Denver Broncos in 2005, then spent three seasons as an offensive assistant with the Houston Texans under Gary Kubiak. He spent another three seasons as an offensive assistant and a wide receivers coach for the Washington Football Team — on a staff that included current head coaches Matt LaFleur of the Green Bay Packers, Sean McVay of the Los Angeles Rams and Kyle Shanahan of the 49ers.

McDaniel followed Shanahan, at the time an offensive coordinator, to a one-year stint with the Cleveland Browns, where he was a wide receivers coach, and then two years with the Atlanta Falcons, where he was an offensive assistant. Shanahan became the 49ers’ head coach in 2017 and hired McDaniel as the run game coordinator before promoting him to offensive coordinator last offseason. In McDaniel’s five seasons in San Francisco, the offense has ranked 11th in rushing yards with the fifth-highest percentage of runs that pick up 10 or more yards.

McDaniel will become the Dolphins’ 11th head coach, interim or otherwise, since 2000, after they employed just three head coaches in their 34 previous years of existence. They fired Flores after he went 24-25 in three seasons, including two of the franchise’s seven winning seasons this century.

Flores filed a racial-discrimination against the NFL, the Dolphins and two other teams last week and alleged that owner Stephen Ross offered him $100,000 per loss during the 2019 season. Ross denied the accusation last week.