Barca took a fourth-minute lead through Andres Iniesta but then twice trailed as Karim Benzema struck a first-half brace and - after Lionel Messi levelled - Cristiano Ronaldo's penalty restored Madrid's lead early in the first half.
But everything changed when Sergio Ramos felled Neymar in the area, earning a red card and giving Barca the first of two penalties, both converted by hat-trick hero Messi.
"La Liga is not over," Martino said. "We were given up for dead but with this result today we are right back in it. This was our last chance. We did not want to be left out."
Barca stay third with the win, but are now only one point from the summit with Atletico Madrid topping Real on head-to-head record.
The match had everything as momentum swung in both directions. Angel Di Maria and Karim Benzema undid the damage of Iniesta's early goal, but Messi scored a brilliant equaliser and then - after Ramos' red - Madrid could not contain their opponents.
Messi's hat-trick took him to 236 in the league, overtaking Hugo Sanchez for second in La Liga history.
"It's difficult to talk about him," Martino said. "You run out of things to say. He is still breaking records. He plays so many great games, especially when it counts."
Neymar's performance brought some criticism, but Martino defended the expensive Brazilian.
"He did not have the best game, but the turning point - the red card of Ramos - comes from him," he said.
"At that moment he was on a phenomenal run. He's only 21 but he can handle the big games."
If they could have hung on to either of the leads they held, Madrid would be seven points clear of Barca, but Carlo Ancelotti downplayed the damage done to his side's ambitions.
"It does not matter so much because we are still in contention for the title," he said.
"We played well. We did not deserve to lose."
Madrid players had been angry with the referee, believing Neymar went down under minimal contact while Iniesta - in winning the fourth penalty - tried to find space that was not there as he tumbled over Xabi Alonso's outstretched leg.
"I do not want to talk about the referee," Ancelotti added.
"He had so many decisions to make. I did not see the foul on Neymar, but this decision changes everything."