The surprising Warriors won their fifth straight and handed Miami only its second home loss of the season.
Miami took a 95-91 lead on a jump shot by Dwyane Wade with 3:51 to play and the Heat did not score another point.
Shane Battier had a chance to put Miami in front with 15 seconds to go, but his 3-point attempt misfired. Green then came through with a layup that went through the basket with nine-tenths of a second showing on the clock.
The Warriors have won 12 of their last 15 games and improved to 9-4 on the road.
Klay Thompson led Golden State with 27 points, Lee finished with 22 and 13 rebounds and Jarrett Jack added a season-best 20 points.
LeBron James had 31 points for Miami, but the Heat lost for the third time in five games.