The story
Unknown, with various theories ranging from spontaneous usage as a nonsense chant, to less likely sources from Arabic, Latin, and Hindi. Some etymologists suggest an origin from Arabic القَسَم (al-qasam, “the oath”).
Etymology from Wiktionary, CC BY-SA 4.0.