Kiprotich took the lead at the 37km mark, despite appearing to suffer discomfort in his leg minutes earlier, and went on to win comfortably.
It was Uganda’s first medal at London 2012 and he won in a time of two hours eight minutes 11 seconds.
Great Britain’s Lee Merrien and Scott Overall finished well down the field.
Kipsang had taken up the running after Brazil’s Franck de Almeida’s early break and led at the halfway stage.
Kiprotich and Kirui caught him up to leave a three-way fight for the gold medal.
The Ugandan looked to be starting to struggle with an injury to the back of his leg, but unexpectedly surged to the front and pulled away.
“It means a lot [to Uganda],” said Kiprotich. “Since 1972 we have never won a gold medal, so they are very happy.”
Uganda’s last Olympic champion was 400m hurdler John Akii-Bua, who won gold at Munich in 1972.