The Germany international, 29, has agreed a four-year contract at the Bernabeu, and will join when his deal at the Premier League club expires on June 30.
A Chelsea statement said: "Chelsea thanks Toni for his contribution to our success over the last five years and wishes him well in his future career."
Rudiger, who will be presented as a Madrid player on July 20, spent five seasons at Chelsea -- winning the FA Cup in 2018, the Europa League in 2019 and the Champions League in 2021 -- but rejected the club's offer of a contract extension.
Madrid were impressed by the centre-back's performances in their Champions League quarterfinal tie in April, when Rudiger scored in a 3-2 second leg win at the Bernabeu which saw Chelsea eliminated 5-4 on aggregate.
The LaLiga club had been contacted by the defender's representatives earlier in the season, but ruled out a move at that point due to the likely costs involved.
Their position changed after the Champions League second leg, and a deal was concluded swiftly, with Rudiger's desire to play for Madrid and a drop in his wage demands viewed as key.
Rudiger's signing is the second time in successive seasons that Madrid have taken advantage of the availability of a top-level defender on a free transfer, after signing David Alaba from Bayern Munich last year. His arrival will see Rudiger, Alaba and Eder Militao compete to be Madrid's first-choice centre-back pairing, although the versatile Alaba could also switch to left-back.
Rudiger played for Stuttgart in the Bundesliga before joining Roma in 2015. Two years later, Chelsea signed him for a fee of €35 million. He became one of Europe's most highly-rated central defenders under coach Thomas Tuchel, starting in Chelsea's 1-0 Champions League final win over Manchester City in May 2021.
Speaking on April 24 when he confirmed that Rudiger would be leaving the club, Tuchel called him "a key figure" and "the kind to play 50-55 games at an outstanding level, a top defender in the last one-and-a-half years."
Rudiger has been a regular for Germany in recent years, starting all four of their games at Euro 2020 and seven of their qualifiers for the Qatar World Cup.