Financial details of the deal were not disclosed, but British media reported that Chelsea had paid an initial £16.3 million ($22.02 million) with a further £1.7 million in add-ons for the 28-year-old.
"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 in a statement.
Chavarria played for Figueres, Olot and Zaragoza in the lower tiers of Spanish football before joining Rayo Vallecano in 2022. He made 125 appearances in all competitions and played a key role in their run to the UEFA Conference League final last season.
The defender's signing boosts new Chelsea manager Xabi Alonso's options at left back following the departure of Spaniard Marc Cucurella to Real Madrid.
Chelsea, who finished 10th last season, begin their new Premier League campaign at London rivals Fulham on August 24.
($1 = 0.7404 pounds)
(Reporting by Aadi Nair in Bengaluru; Editing by Peter Rutherford )