The gold was Uzbekistan's second of the afternoon and third of the boxing tournament.
Russia's Vitaly Dunaytsev and Germany's Artem Harutyunyan won the bronze medals.
Sotomayor, whose father is a cousin of Cuba's 1992 Olympic high jump champion Javier Sotomayor, had beaten Gaibnazarov before and shed tears of disappointment at the upset.
"In the second round he surprised me with a hit but in the third one I think I was able to get ahead," added the man who beat Cuba's Yasnier Toledo in the quarter-finals.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
Taller and with a greater reach than his opponent, Sotomayor had hoped to give Azerbaijan, his home since moving from Havana in 2013, the country's first boxing gold but it was not to be.
"The judges saw it differently and it's their decision and it's the kind of decisions that happen in boxing," he said.
(Reporting by Alan Baldwin, editing by Ken Ferris and Brian Homewood)
