Prep- Whether you are playing a published adventure or making your own, there are lots of differing opinions on how much time to spend prepping. Some DMs like to have ever possible detail worked out in advance, and some just make everything up as they go. Find the method that works best for you, but in general you should consider making some point form notes before each session so you have at least a general idea of the encounters that could happen, the NPCs the PCs might meet,, and where you'd like the story to go. Just remember one thing... if your players can go outside the box, they will go outside the box. At least some times, anyway. There will always be times when the players do something you didn't expect. THAT'S OKAY! Roll with it! If you can, just make it up and make it seem like you were prepared for them to do that, even if you weren't. If you aren't comfortable with "winging it" when the players do something unexpected, calmly call for a brief pause for snacks, or a washroom break, and take a few minutes to figure out what you will do next. Don't panic, it's going to be okay.
Take notes- Make notes before the session starts in point-form for what you expect to happen in the session; make notes about the monsters coming up and any special abilities you might need to remember, and during the game make notes about any NPCs you need to make up on the fly, or things the Characters do or say that you can mine for story ideas and encounters later. The more notes you take, the more you have to work with going forward. I like to make a bunch of characters beforehand and then throw them into the story and I have notebook to keep all of that straight and I'll talk more about that in the next part.
NPCs - Make a list of NPC names common to the region the PCs are in, or to the races they might encounter. As the session progresses, if they meet an NPC you weren't expecting them to meet, if you make up an NPC on the fly, you can pick a name quickly from the list (make sure you make a note about it in your notes for later!). It is much more realistic for your players if the people they meet have names, rather than Bartender #4, or Generic Old Woman. You can also keep a list of NPC characteristics handy for the same situations (ie. Smokes a purple pipe; Has only one eye; likes to say "Wot!" at the end of every sentence; Fidgets with an a dead rat.). I also like to write little stories or hooks that random characters can have and I attach those to a character that I've made before the game starts and if they run into that character somehow then they have an opportunity to go on a little Quest or at least explore some very unique thing about them that might incorporate NPC into the story.
Remeber for all you new DM's out there Don't panic, it's going to be okay.