Hakan Calhanoglu belatedly gave Hamburg the lead in the 80th minute and Mike Frantz's own goal doubled their advantage before Josip Drmic managed to score Nuremberg's consolation goal on the stroke of full-time.
At the final whistle Hamburg had clinched only their second Bundesliga win of the year to draw level on points with 15th-placed Nuremberg, who have now failed to win any of their last three matches.
Hamburg had the first chance of the game in the fourth minute but Calhanoglu shot over the bar from distance.
The hosts had another opportunity from a counter-attacking move but this time Calhanoglu was stopped by Nuremberg goalkeeper Raphael Schafer.
The visitors came close in the 25 minute as Markus Feulner rattled the right-hand post with a fierce drive.
Hamburg thought they had taken the lead just before the break as Calhanoglu crossed from the right to Jacques Zoua, but the Cameroonian's shot clipped a post and went out of play.
Hamburg nearly scored the opener in the 70th minute, only for Javier Pinola to clear Zoua's header off the goal line.
The hosts finally broke through with 10 minutes remaining as Calhanoglu danced his way around Hanno Balitsch before hitting the ball over Schafer and into the far corner.
The game looked over when Hamburg went 2-0 up six minutes later thanks to Frantz, who turned Petr Jiracek's cross into his own goal.
Nuremberg pulled a goal back a minute into stoppage time as Drmic placed his shot perfectly inside the right-hand post, but it was a case of too little, too late.