The story
Likely imitative of non-verbal sounds used to indicate disagreement or discomfort. Compare nope, wherein the -p may represent closure often uttered at the end of the word no. Compare also um used to indicate hesitation. Attested from 1888.
Etymology from Wiktionary, CC BY-SA 4.0.