The third seed battled through temperatures of up to 42 Celsius (107.6 Fahrenheit) and a third set lasting nearly two hours to overcome the 44th-ranked Knapp 6-3, 4-6, 10-8. (Agencies)
The four-time Grand Slam champion was forced to stay on court for three hours 28 minutes as she seeks her first major title since the French Open in 2012.
The conditions were so tough that organizers suspended play at the tournament midway through the third set. However, under tournament rules, Sharapova and Knapp had to finish the set before coming off.
"It was tough for both of us and we both fought as hard as we could," Sharapova said.
"The recovery for me will be really important but these are the matches you train for and I'm really happy to be through."
Now under coach Sven Groeneveld after a failed, one-tournament partnership with Jimmy Connors, the 26-year-old is coming back from shoulder surgery, and she struggled against Knapp.
Her serve let her down and she only converted seven of 20 break points.
Sharapova got the match at Rod Laver Arena underway by holding serve and Knapp did the same as the two players got the measure of their games.
Sharapova had struggled with her serve in the first round and it again posed a problem, with three double faults in the third game allowing Knapp to get an unexpected break.
But the Italian failed to make the most if it, losing her next service game to love as Sharapova's probing baseline shots started finding their mark.
The Russian, at her 11th Australian Open, which she won in 2008, held serve to go 3-2 in front and began applying the pressure, finally getting another break but not before throwing away three break points.
Sharapova held as Knapp started wilting in the oven-like conditions and she served out the set before donning an ice vest and gulping water at the changeover as she desperately tried to cool down.
They both held their opening serve in the second set before a feeble Knapp double-fault put Sharapova 2-1 in front, only for the Italian to level at 2-2 when her opponent sent a forehand long.
It went with serve in close-fought games until backhand into the net gave Knapp three set points and a backhand long made it one set apiece.
The heat rule was in effect, giving them a 10-minute break between the second and third sets, and Sharapova returned refreshed, firing cross-court winners to break for 1-0.
But she then failed to hold serve, as did Knapp with the Russian again gaining the edge. Once again, Sharapova was broken to leave the match finely poised at 3-3.
She got another break and had three match points in the 10th but threw them away and with Knapp then holding, Sharapova had to serve twice to stay in the match before breaking in the 17th and serving out for victory.
Sharapova, who returned from injury at the Brisbane International this month, next plays French 25th seed Alize Cornet.
The third seed battled through temperatures of up to 42 Celsius (107.6 Fahrenheit) and a third set lasting nearly two hours to overcome the 44th-ranked Knapp 6-3, 4-6, 10-8.