Gavi scored with a low curling left-footer at the record age of 17 years and 304 days, levelling the first-half score at 1-1 just before halftime.
Martinez blasted his header just over the line off the crossbar in the last minute of the game to hand Spain a draw.
The Czechs went up twice with counter-attack goals by Jakub Pesek and Jan Kuchta in the Group B, League A game.
Luis Enrique swapped eight players in his starting XI from Thursday’s 1-1 draw with Portugal as only goalkeeper Unai Simon, Gavi and Pablo Sarabia kept their posts.
His men were dominant throughout but it was the hosts who struck first only four minutes into the game.
Vladimir Coufal started a fast counter-attack on the right flank, finding a sprinting Kuchta who produced a perfect pass for a tap-in by Pesek.
The Sparta Prague midfielder was scoring his fifth goal in 12 international games.
Gavi levelled three minutes into the first-half stoppage time following a pass from Rodri who had capitalised on a poor clearance.
Spain kept pushing but the hosts struck on a counter-attack again in the 66th minute as Vaclav Cerny sent Kuchta dashing through the defence and the striker chipped the ball over an advancing Simon.
Second-half substitutes Marco Asensio and Ferran Torres hit the post, while Kuchta missed narrowly on the other side on yet another counter-attack.
With a minute to go, Asensio found Martinez with a cross from the left side and the Athletic Bilbao defender was on target.
Spain will next face Switzerland in Geneva on June 9 while the Czechs are due to take on Portugal in Lisbon on the same day.