Things that discourage you, or make you lose confidence, are demoralizing. It can be demoralizing to study hard for a test and do badly on it.
When you are rejected — getting turned down for a job or a date or a scholarship — it's demoralizing. If people whose opinions you value put you down or belittle you, that's demoralizing too. A more old-fashioned meaning of the word is "corrupting someone's morals," from the French démoraliser, which is thought to have been coined during the French Revolution.