There's a famous cartoon by Sidney Harris that shows scientists at a board pointing at a complex proof. Between all the math, someone has written, "Then a miracle occurs." Obviously, this is unsatisfying, and yet that comic is so popular because it's captured something very true.
I know a lot about the writing craft. I have a master's degree in writing, have spent my entire adult life making a living this way in one field or another, have done much study and practice on my own, and have attended more workshops than I can count. I've worked with excellent and talented editors, many of whom taught me more than all my formal training put together. I have published hundreds of thousands of words of fiction and nonfiction, and written many hundreds of thousands more.
When it comes down to it, I still don't know what goes on when I write my stories. The day before something is due I often don't know how the hell I'm going to make it work and get to the end.
And then a miracle occurs.
(Note: It pleases me thematically to schedule this post for Christmas Eve, but I don't intend to say that miracle is Jesus or anything.)