The 23-year-old centre-back has spent the season on loan at Valladolid, but injuries have restricted him to just two appearances.
However, the Pucela have seen enough talent and potential in Sanchez to sign him.
Sanchez joins Valladolid for around €5m, signing a long-term contract until 2024.
A technically sound, ambidextrous player, Sanchez had been at Real Madrid since the age of eight.
He made five appearances for Madrid’s first team in the 2018-19 season, two of them in the Champions League.
✍🏻💜 Acuerdo con el @realmadrid para el traspaso de Javi Sánchez. El central firma hasta 2024. ¡Enhorabuena!
— Real Valladolid C.F. (@realvalladolid) June 16, 2020