The Frenchman won three back-to-back Champions League trophies, culminating in this year's victory over Liverpool, and a La Liga title as Madrid coach.
Zidane revealed his departure in an unscheduled press conference at midday on Thursday.
"The team needs to continue winning and needs a change," Zidane told reporters.
"First for me, the squad, the club, I think it's a bit of a weird moment but an important one that is good for everyone. What I think is that this team needs to continue winning, but I think it needs a change, a different voice, another methodology.
"I love this club and the president who gave me the chance to play for this club and manage the club of my dreams. But everything changes and that's why I've taken the decision to leave."
Real president Florentino Perez said of the 45-year-old's departure: "This was a totally unexpected decision and today is a sad day for me and for everyone who works for this club. When he says he's taken a decision though, we have to accept it. I tried to convince him but I know how it is. He knows he has all our love and support."
Zidane took over as coach of the club he previously represented as a player in January 2016.