Villarreal had seemingly blown a three-way battle for the title with Barcelona and Sevilla wide open when quickfire second-half goals from Manu Trigueros and Cedric Bakambu had the hosts 2-0 up at Estadio de la Ceramica.
However, Madrid - beaten by Valencia last time out - produced an emphatic response with three goals in 19 second-half minutes to avoid back-to-back losses and seal three points that sees them go back top of LaLiga with a game in hand.
The visitors were second best throughout much of the match, but Gareth Bale - starting for the first time since November after an ankle injury - led the comeback with a well-placed header in the 64th minute.
The ever prolific Cristiano Ronaldo then restored parity by becoming LaLiga's leading penalty scorer with 57 after Bruno Soriano was harshly penalised for handball in the area.
And substitute Morata secured a vital three points, which leaves Madrid one clear of second-place Barca, with six minutes to go when he headed home Marcelo's cross to spark joyous celebrations from the visitors.
Madrid had the luxury of knowing exactly what they had to do before the match even started following wins for Sevilla and Barca this week.
But that did not make their task any easier as Villarreal wrested control and looked a threat going forward, with Mario Gaspar forcing Keylor Navas into a smart 12th-minute save.
The hosts had to rely on Sergio Asenjo soon after, though, the goalkeeper slapping the ball away from under the crossbar after Victor Ruiz inadvertently directed Marcelo's cross towards goal.
But Villarreal's assault resumed just before the half-hour mark. Jonathan dos Santos first saw an effort deflected just wide, before a stretching Samu Castillejo met Adrian Lopez's cross and shot over from six yards.
Madrid were offered encouragement when Asenjo was forced off with an apparent ankle injury 10 minutes before the break, though Villarreal remained in control until the interval.
The hosts started the second half as commandingly as they finished the first and their superiority finally bore fruit.
Castillejo did well to hold off Marcelo and nod down a lofted pass in the area, teeing it up nicely for Trigueros, who rifled a half-volley past the helpless Navas.
And Villarreal had a second six minutes later.
Bruno produced a defence-splitting pass from the centre circle to find the run of Bakambu right through the middle and he coolly slotted into the bottom-left corner from 20 yards after shrugging off Sergio Ramos.
Villarreal had a lucky escape shortly after when Ronaldo unleashed a left-footed volley that came back off the right-hand post.
But Bale was not to be denied as he rose highest to meet Dani Carvajal's cross and headed past substitute goalkeeper Andres Fernandez.
Madrid clawed themselves level 16 minutes from time with Ronaldo slamming home a penalty after a Toni Kroos shot was controversially adjudged to have struck the arm of Bruno.
Morata then completed the astounding turnaround in the closing stages by meeting Marcelo's fine left-wing cross and beating Andres with his head, despite the goalkeeper getting a hand to it, leaving Madrid to focus on Wednesday's clash with Las Palmas on the back of a priceless win.