The hosts took an early lead in the Group A2 clash after Sparta Prague forward Jakub Pesek scored from close range in the fourth minute, connecting with a pass from Jan Kuchta who got in behind Spain's defence.
The visitors equalised on the strike of half-time when Spain midfielder Gavi, one of three players to keep their place in the team after coach Luis Enrique made eight changes from the 1-1 draw with Portugal, beat Czech goalkeeper Tomas Vaclik with a shot to the far post.
The goal for Gavi saw him pass Ansu Fati as Spain's youngest goal scorer in senior national team history.
"I know Gavi very well," said Spain manager Luis Enrique. "I have been watching videos of him for five years. If there was one player up for it in the first half, it was him. He has an unstoppable conviction when he plays. I'm not going to talk about Gavi anymore.
"I already told you he would score goals and he will keep scoring goals. The best thing about him is he's the complete package: defending, attacking, courage, character and he has so much quality."
The Czech's retook the lead in the 66th minute after Gavi's strike when forward Jan Kuchta lobbed goalkeeper Unai Simon from just outside the area after he was sent through on goal alone.
Spain scored in the 90th minute to break the hearts of the home fans when Martinez connected with a cross from Marco Asensio and his header just crossed the line.
Luis Enrique added the game was "very complicated" for his side.
"It was a complicated game from the first chance, we were not ourselves for the most of the time, we did not manage [the game] as well as we wanted," Enrique told a news conference.
"We had more chances, but especially in the first half, we had a problem to play against such a strong, aggressively playing team with an excellent defence. We lacked fluidity, so the match was really very complicated."
In their five previous encounters, the Czechs only once managed to get at least a point against Spain -- a goalless draw in 1996. They previously scored their only goal against Spain in a Euro 2012 qualifier in 2011.