Leonel Manzano of the United States snatched silver 0.71s behind, with Morocco's Abdalaati Iguider taking bronze.
Makhloufi was reinstated to the final on Monday after initially being disqualified by the IAAF for not trying in his 800 metres heat.
His decision to rest his legs paid off as he sprinted away from the pack in an otherwise mid-paced race, finishing in a time of 3:34.08.
"It's the will of God. Yesterday I was out, today I'm in," Mahklouf said afterwards. "This is a gift for the Algerian people and for the whole of the Arabic world."
Kenya's favourites flopped, with Silas Kiplagat fading to seventh and defending champion Asbel Kiprop struggling with a hamstring problem in last place as they paid the price for failing to dictate a quick pace that would surely have kept the big-finishing North Africans and American out of contention.
Eyebrows have been raised at Makhloufi's two 1,500 runs in London, but he has form in similar circumstances - he won gold in this year's 800 at the African Championships with a quick finish after the East Africans got their tactics wrong.
And they played into the 24-year-old's hands again, failing to stretch the field in the opening stages and allowing the relatively powerful Algerian to power away to a final 100m of 12.6 seconds, with Manzano following suit to race through for silver.
Makhloufi did not need to break his personal best of 3:30.8, and it appears his gamble of effectively forfeiting the 800m for this final paid off - he showed no signs of the injury his team used to successfully appeal his initial disqualification, which was the result of an error from his federation in failing to withdraw him before the deadline.
Whether it was gamesmanship or a simple physical decision is irrelevant - Makhloufi is the first Algerian man to be Olympic 1,500m champion since Noureddine Morceli in 1996.