Czech player Hlavackova, 125 places higher than her Serbian opponent in the world rankings, was expected to breeze through but lost the first set 6-1.
A dramatic second set featured six breaks of serve and ended in a tie-break, which Hlavackova won 13-11 to get back on terms, but Krunic - who broke three times in each set - took the decider 6-4.
Third seed Mandy Minella fared better, the Luxembourg player beating China's Qiang Wang in three sets.
Minella lost a tight second set but was otherwise dominant in a 6-2 5-7 6-3 win.
Kamilla Farhad provided little for the Azeri fans to cheer, losing 6-1 6-0 to Russia's Alla Kudryavtseva.
There were three-set wins for Thailand's Tamarine Tanasugarn and Russia's Valeria Solovieva, over Varvara Flink and Olga Savchuk respectively.