Benitez, who began his coaching career in Madrid's youth academy, had returned to the Spanish league where he led Valencia to titles in 2002 and 2004 before joining Liverpool, where he won the 2005 Champions League.
"It's an emotional day, one when I return here, to my home," Benitez said at the Santiago Bernabeu Stadium. "I hope things will go well and that we win many titles."
Madrid said Benitez was the right choice because he understood the values that underpin the club, and what it meant to be part of it.
"He is a product of this house," the club said in a statement, detailing how the 55-year-old Benitez played as a defender in youth teams and "began his coaching career here."
Ancelotti guided Madrid to its 10th European Cup in 2014, but was let go after the team failed to win a major trophy this season.
"Today we begin a new phase with the full conviction that the arrival of our new coach will strengthen us," said Madrid president Florentino Perez, introducing Benitez as "a man who breathes football, professionalism and the very ethos of our club."
Perez highlighted Benitez's ability to communicate with players and his habit of making detailed preparations of each game.
Benitez is Madrid's eighth coach in 10 years. He will be tasked with ending Madrid's dismal record of one Spanish title in seven seasons despite counting on Cristiano Ronaldo and record revenues.
Madrid finished two points behind Barcelona in the Spanish league, and lost to Juventus in the Champions League semifinals.
Benitez will need to grapple with three problems that dogged Ancelotti in his final season: Find a way to rise above Barcelona; win the Champions League; and get the best out Madrid's star-studded squad.
Playing second fiddle to Barcelona has always grated with Perez and the board of directors. The club's last Spanish league title came in 2012 under Jose Mourinho, while Barcelona has won five titles in seven seasons, the other one going to Atletico Madrid in 2014.
"When I arrived at Liverpool I was given three years to be competitive," Benitez said. "Fortunately we won the Champions in the first year, but here it's different."
Apart from being considered a hard-working disciplinarian who believes in player rotation, Benitez was regarded as one of the game's thinkers.
Madrid said Benitez was used to the pressure of leading large teams in Spain, Italy and England.
"Benitez is a methodical strategist, a tireless worker, and student of the game," Madrid said, calling him "one of the best coaches currently in the sport."
Benitez left Naples early Monday, a day after coaching Napoli's last game, a 4-2 home loss to Lazio. Had Napoli won, it would have finished third and secured a Champions League spot. Napoli finished fifth.