The transfer fee is around 16 million pounds and the contract expires in 2031.
Chavarria arrives after four productive years at Rayo, where he established himself as a reliable La Liga defender and helped the club secure consecutive eighth-place finishes.
He made 44 appearances in all competitions last season as Rayo reached the Conference League final, ultimately losing 1-0 to Crystal Palace.
The move represents another step in an unconventional career for Chavarria, who did not make his La Liga debut until he was 24.
Born in Figueres, Catalonia, he began with hometown side UE Figueres before moving to UE Olot in 2018. His progress continued with Real Zaragoza, where he made his professional debut in 2020 after playing in Spain's lower divisions.
Two years later, Rayo gave him his opportunity in the top flight after signing him for less than 2 million pounds. Chavarria went on to make 125 appearances for the club, becoming an important figure on the left side of their defence.
His performances have now earned him a move to one of Europe's biggest clubs, while also providing Chelsea with additional experience following Marc Cucurella's departure to Real Madrid.
Chavarria is Chelsea's 11th new arrival of the transfer windown and continues a noticeable shift towards more experienced recruits. The club have also brought in players such as Danny Welbeck and Jordan Henderson, having previously focused heavily on younger signings.
The Spaniard believes the move represents a major opportunity.
"This is a dream for me as Chelsea are one of the biggest clubs in the world. It is a big opportunity but I am prepared and will work hard to help the team achieve success," Chavarria said.
He added: "There are a lot of people who have helped me get to this moment and I have to thank my family. They have always supported me and today is only possible because of them."