The 19-year-old has impressed since joining Zorya from Dnipro Dnipropetrovsk last year, helping his new club to secure Europa League qualification for next season.
Lunin's form saw him called up to the Ukraine national team, earning his first cap for his country in a 1-1 draw with Saudi Arabia in March.
The player's permanent transfer to the La Liga giants was confirmed by a short club statement released on Friday, which did not disclose the fee paid.
"Real Madrid and FC Zorya Luhansk have agreed the signing of the player Andriy Lunin, who will be attached to the club for the next six seasons," the statement said.
Zorya turned down a bid from Spanish outfit Real Sociedad for Lunin in January, while Inter Milan were also credited with an interest in the youngster.