"Vagary" is one of a number of words from Latin or Romance languages that had a long, stressed vowel in the second-to-last syllable in the source language, but that can be pronounced in present-day English with the stress shifted to the third-to-last syllable.
The Oxford English Dictionary says "probably < Latin vagārī (Italian vagare) to wander". (Italian "vagare" is pronounced [vaˈgaːre].)
Other words like vagary that used to be pronounced with stress on the second syllable (some still can be) are balcony (< Italian balcone [balˈkoːne]), abdomen (< Latin abdōmen) and acumen (< Latin acūmen).
While the etymology somewhat explains the existence of the variant with stress on the second-to-last syllable, there are also words with somewhat similar etymology where as far as I know the stress has been on the third-to-last syllable for much longer, such as plethora (< Greek πληθώρα, its derivative Latin plethora, and its derivative French pléthore; the OED says "In 18th-cent. dictionaries the word is occasionally recorded with stress on the second syllable (Bailey (1731, 1735)), apparently following the ancient Greek stress") and retina (< Latin retina, with the suffix -ina that had a long "ī" in Classical Latin).