Practice makes perfect!
I’d say the most important thing is knowing who your NPCs are and what they want. That’s what you should prepare outside of sessions. Once you have that, it’s a lot easier to deal with players throwing curveballs.
A constrained scope helps as well. Give the group a prompt like “make characters who want revenge on the Lich Queen” or “make characters who care about the city of Korvosa.”
“Watch the Irishman Suffer” is practically it’s own genre of Star Trek episode. Chief O’Brien needs a break, he’s just a regular dude who has witnessed his own death too many times.