If a writer makes a forceful contrast between expectations and reality, creating a surprise ending for readers, the literary device he or she is using is called irony.
Irony is achieved when there is a huge contrast between what can be and cannot be achieved.