We hope you haven't had too much experience with flunk, which first appeared as U.S. college slang in the early 19th century with the nonacademic meaning of "to give up" or "to back down." The editors of the Yale College magazine The Crayon used it that way in a plea for subscribers.
To joke in earnest, … we must have at least as many subscribers as there are students in college or flunk out.
— The Crayon (Yale College), 1823.
Some etymologists believe the word is a blend of flinch and funk, which both refer to an act of withdrawing or shrinking from. The case for funk is bolstered by its use at Oxford University in the 18th century to refer to a state of panic or fear, potentially developed from obsolete Dutch fonck, meaning "perturbation, turmoil, agitation."
Pryce, usually brimful of valour when drunk, / Now experienced what schoolboys denominate funk.
— Thomas Ingoldsby, "Patty Morgan The Milkmaid's Story," 1840
Considering one's emotional state after failing an exam or course, funk is a fitting derivative.
What is definitely known about flunk is that it has been enrolled in the language since at least the 1840s, and students have been in a funk over flunking out since the early 20th century.