Tomljanovic took the first set in a tie-breaker, but was sluggish in the second and allowed Martic to draw level.
In the decider, the Aussie was 4-1 and a double-break down, before she rallied to win five games on the bounce to take the match.
AS IT HAPPENED: Australian Open 2024 day four
Tomljanovic admitted in her post-match interview with Alicia Molik she was just about out of petrol, but the energy from a strong crowd on John Cain Arena pushed her over the line to record a 7-6 (3), 4-6, 6-4 win.
“I really was out at one point – I felt like she was kind of toying with me and I couldn’t read her serve,” she said.
“But you guys never gave up even more than me, so I was like, ‘If you are here, I should give it my best’.
“If it wasn’t for you guys I could have maybe been 2-6 in the third.”
Down 5-4 and serving to keep herself in the match, Martic coughed up two double-faults in a row to put Tomljanovic up 15-30.
“Oh my word … she must be reeling,” Sam Smith said in commentary for Nine.
Tomljanovic did the rest all herself though. She brought up match point with an “unbelievable” forehand winner, before a Martic slice found the net.
“A classic Ajla Tomljanovic comeback … what a night,” Smith said.
Having come through the Croation ranks more or less on a similar trajectory, Tomljanovic and Martic were close friends before the former moved to Australia and naturalised.
The Aussie said Martic never allowed her to really settle into the match.
“I felt like I really had to hang in there because I knew it could turn on a dime,” she said.
“And yes, there was a bit of luck involved tonight and I will take it.”
Tomljanovic’s victory wrapped up the first round of competition. She will take on No.11 seed Jelena Ostapenko – who on Tuesday beat another Australian, Kimberley Birrell, in straight sets.