One thing we learn in almost every single episode of Doctor Who is that the universe can be a dangerous place. Flesh-eating shadows, merciless robots and gigantic arachnids roam the galaxy like it's their own personal playground, and considering that the Doctor is thousands of years old, it's not surprising that the character has suffered countless notable defeats in that long lifetime.
Things don't always result in a cheery stroll back to the TARDIS once the day's adventure has come to a close, and across the classic and modern incarnations of the show, the character has led companions to their deaths, watched the stars explode, killed his own people, and ran into many situations that simply prove unwinnable.
Even though the BBC will never kill off the title character of their flagship show, the Doctor's hijinks usually come at a cost, and often, that cost is high. Things do tend to work out eventually (the show must go on, after all), but the road to get there is rarely smooth, and the ancient Time Lord has tasted many instances of defeat as a result.