I used to do this all the time, and still struggle occasionally. One of the biggest mistakes I made was having an NPC sheet with the fact they were a double-agent written on it. Of course, when I described the NPC to the players I called them a double-agent and gave the game away....doh!
The main thing I've found that helps to prevent this from happening is to pause and think. It's very easy as a GM to get caught up in the game and forget that thinking time is OK. Before your NPC speaks, stop and consider what they will say. Double check that it makes sense, and that that particular NPC would say those things in that particular situation. This has helped me immeasurably. I used to really worry about player down-time, but have found that taking a breath or three occasionally really helps to give me time to get things straight in my head before I speak.
Regarding fixing the situation you currently have, I've found over and over again that being honest with the players is the quickest, easiest and most effective approach. Tell them you made a mistake, and if possible ask them to separate out character and player knowledge so they don't meta-game. In the case of the tunnels, the players know this but the characters don't, that kind of thing. How effective this is may vary, as I know some players find it very difficult not to metagame in this way.
Another thing you can do is change the world to invalidate the things you accidentally revealed. Nothing is written in stone with your story and the world so change it. If you do this though, it's only fair to warn the players that the information they have is no longer valid. You don't have to say why, or what has changed, but letting them know will prevent them from acting on information they believe is accurate and useful when it no longer is.
If you want something in-game, then the NPC might believe what they said was true and accurate, but there's no guarantee it actually is. Maybe they're wrong, maybe they're lying, maybe they've been lied to......the permutations are endless.
Above all, don't worry. This happens to us all, and will continue to crop up occasionally.