A recent discussion on Google+ got me thinking about improvisation as a gamemaster. Some of my favorite experiences running Savage Worlds have come directly from a player haring off in a random direction that I didn't plan, and needing to adapt on the fly to what they wanted to do. As an example, here's the story of "Short Tom".
In the first playtest of Children of the Apocalypse, the players were trying to negotiate a treaty between their home city-state and a larger, more powerful neighbor. One of the players decided he wanted to get the lowdown on the local criminal population, and made an amazing multi-raise Streetwise roll. Suddenly, I needed to invent a contact for this player to connect into the local population of rogues. I directed him to a seedy tavern, and then had the bartender direct him to "Short Tom" in the back. "Short Tom" was a pointman for people seeking under-the-table extralegal services. To add some fun, I decided "Short Tom" was a job, not a person, and so when the player came back looking for "Short Tom" the next day, it was a completely different person.
OK, so where did all that stuff come from? Two basic answers: first, tropes. The more tropes you know, the easier it is to drop them in to an adventure when you have nothing prepared. Tropes work because they're expected; it makes sense to the players that a criminal contact would be at a back table in a seedy tavern and operate under a pseudonym. If you're willing to fall into a bit of a black hole, TV Tropes is an amazing (and enormous) resource for pulling tropes out of popular TV, movies, comics, and fiction.
And that brings me to the second answer - genre immersion. Whatever genre game you're running, read, watch, and listen to as much material from that genre as possible. Running a gritty SF game? Watch Battlestar Galactica (the new one, obviously), read the Expanse series, go peruse the rulebooks for games like Eclipse Phase and Nova Praxis. Immersing yourself in the genre lets you pull ideas from multiple sources, which avoids purely derivative ideas (there's a mysterious Ranger in the back of the tavern, and, um, yeah, he's actually the lost heir to the throne!), but also gives you a chance of coming up with something interesting when the players go way, way off plan.
(And for my favorite media example of players going not just off the rails, but off the entire planet, check out Darths and Droids.)