Rahimov, who served a two-year doping ban after testing positive at the 2013 Universiade, when he competed for his native Azerbaijan, was 12kg behind when the favourite Lu Xiaojun of China finished his lifts.
Rahimov had to lift 214kg to win, 4kg more than Lu's clean and jerk world record, which he set three years ago.
When Rahimov made the lift the Kazakhstan national coach, Aleksey Ni, ran on to the platform to hoist his hero off the ground. Ni then fell on to his back and kicked at the air.
During Ni's reign as head coach Kazakhstan has amassed the worst doping record in world weightlifting, with 32 positives since the 2008 Olympics.
Their four champions at the 2012 Games and their one from 2008 have all tested positive retrospectively.
On the basis of that record Rahimov was asked, "What would you say to Olympic fans who doubt the validity of your medal?"
His reply was, "I am not aware of the problem so that is what I would tell them."
Lu, who had broken his own snatch world record with a lift of 177kg, said of Rahimov: "I met a stronger competitor. I admire him." Both men finished on 379kg, Rahimov winning by virtue of his lighter bodyweight.
The bronze medallist, Egypt's Ihab Mohamed, said, "There are Egyptian athletes waiting to be promoted into medal positions because of the doping (at 2008 and 2012 Games). I hope this was a 100 percent clean competition."
Ihab, from Al-Fayoum, is one of six brothers, all weightlifters. He is the only one competing at this level and he is assured of a hero's welcome after the Games, he said, because he is the first Egyptian to win a medal in men's weightlifting since 1948.
Earlier in the day, Sara Ahmed had finished third in the women's 69kg, becoming the first Egyptian woman to stand on the Olympic podium in any sport. "Egyptian weightlifting is born again," said Ihab. "In Tokyo 2020, Egypt's position in world weightlifting will be different."
Lu wore a pair of specially made gold shoes in the expectation of retaining his Olympic title. After he made his sixth and final lift he clearly thought he had done enough to win, as he stripped off his top and screamed in triumph.
But Rahimov had the final say.