In what may have been the best game so far, Spain fell behind in the first half with a goal against their side of Pedri near the halfway line after goalkeeper Unai Simon left a passes back past it.
But the triple European champions regained their composure and seemed on their way to a comfortable victory with goals from Pablo Sarabia, Cesar Azpilicueta and Ferran Torres.
Showing the spirit that led them to the last World Cup final, Croatia made a stunning comeback with goals from Mislav Orsic in the 85th minute and a header from Mario Pasalic in added time to force extra time.
Luis Enrique’s side showed formidable character, however, and won with a superb strike from Morata in the 100th minute and a goal from Mikel Oyarzabal in the 103rd.
Spain celebrated a first knockout victory in a major tournament since Euro 2012 to set up a quarter-final against France or Switzerland in St. Petersburg on Friday.
“It was an epic game,” said Luis Enrique.
“I have had many intense games in my career, but this was one of the best. An infinite number of things happened to us, but we knew how to change it. Everyone saw our true team spirit today.
Scorer Azpilicueta added: “We have suffered so much, it has been so long since we won a knockout game and we finally managed to do it against the World Cup finalists. “
Croatia come home with their heads held high but still waiting to win a Euro knockout game.
“At the start of extra time we had them on the ropes but we failed to score on two good occasions. Then the game reversed and we didn’t have the strength to come back, ”said midfielder Luka Modric.
Coach Zlatko Dalic added: “We did everything we could, we reduced the score to 3-3, we had a few chances, but we couldn’t win it in the end. “
Morata responds to criticism
Morata has been the center of attention in the Spanish campaign amid inconsistent performances and criticism from his own supporters, who took a bad turn in last week’s 5-0 win over Slovakia.
His wife and children were threatened by supporters in Sevilla and he complained that he had been subjected to death threats before the match, prompting coach Luis Enrique to urge the police to act.
The forward has long struggled for consistency in front of goal in a career that has taken him to Real Madrid, Chelsea, Atletico Madrid and Juventus, as he has been accused by former coaches and teammates to have a fragile temper.
But here he showed steel when Spain’s confidence was on the ground, controlling a Dani Olmo cross with one foot before slamming into the roof of the net to put Spain back in front.
Substitute Oyarzabal struck moments later from another Olmo cross to increase Spain’s lead and this time Croatia had no response.
The result made them the first team of a Euro to score five or more goals in consecutive matches, with Morata joining Fernando Torres as his country’s top scorer in the competition with five goals.
Pedri set an undesirable record: his own home goal at 49 meters was the longest home side goal by a Euro and the very first in the tournament outside the box.