I've actually had something similar happen and can give an honest answer. I woke early one morning to the sounds of shattering glass. Instinct took over from here, as my heart started pounding and I fumbled for my dresser for the handgun I keep there. I opened my door and stuck my head out to look, and that's when I had the luckiest moment in my life. A bullet lodges in the doorframe a couple inches from my head. I aimed and quickly put two rounds into the intruder's chest. There was no thinking, no real "I'm gonna die I'd better shoot" or anything like that, just pure instinct and fear.
I called 911, and by the time the paramedics arrived, the man was gone. There's no duty to retreat clause here in NC, so I only had to answer some questions from the police before I was free to go. Still haunted by that night sometimes. I'd advise to retreat or disarm the person if possible, because once you take someone's life, it stays with you forever. Even if it was the "right" thing to do.