Today I'm going to address a common novice writer's error: deus ex machina, literally "god from the machine." Writers who write their heroes into a corner and can't find a way to help him escape sometimes resort to an extraordinary and convenient rescue. Maybe someone with magical powers comes in at the last minute and swoops him out of danger. It's a convenient and weak plot device to quickly solve what might otherwise seem an insurmountable problem.
How do you avoid it? Simply put, write carefully. Think about the danger or conflict you want to put your hero in (what's a book without a little danger and conflict for your hero to overcome?), and think of one or two ways to get him out of it, that are not contrived. Give him the tools to do that, spread throughout the book, so that it doesn't feel like just a convenience that he happens to have that nifty skeleton key in his pocket that no one saw until this crucial moment. Give him a reason to have that skeleton key in his pocket in Chapter One, and now you're talking.
Convenient plot points are lazy writing. Find a way to make them less so. More necessary and inevitable to the plot. Critique partners are great for this. They can point out those convenience twists and help you smooth them out. The result is a better and more likely read that will have your reader cheering, because the hero will be the one doing all the work of getting out of danger--not that god from the machine.