Hernandez was under contract until 2021 with Atletico but, in a statement, the club said the French youngster rejected "several" offers to renew terms, along with advances from other European clubs.
"[Hernandez was] stating repeatedly his firm desire to play for Real Madrid," the statement read.
A fee has not been disclosed for the transfer, although Madrid sports newspaper Marca reported it was worth in the region of €26 million.
Hernandez will be presented at the Santiago Bernabeu on Monday after undergoing his medical.
He played 38 times in all competitions for Alaves last term but never made a competitive appearance for Atletico despite joining the club's academy setup as an 11-year-old.