In writing, most of the books that fail do so because they're somewhere between stunningly mediocre and perfectly wretched. That's because most of the books that people write are somewhere between stunningly mediocre and perfectly wretched. Luck is going to go to those of a higher quality than that, but unfortunately, not to all the good books that are written.
Say what you will about how bad some books are and yet have gone on to huge success, the prose might be plodding, the plots improbable, and so on and so forth, but they all delivered something that a great many readers wanted very much. They were very good indeed at something and passable at some other things (even if they were rather poor at practically everything else) and people who don't like them would be far less conscious of their failings and more generous in evaluating their strengths if they had only modest sales. (And that's not envy that makes us unwilling to acknowledge whatever such a writer does well. Or only a little bit of it's envy. It's also a huge frustration that not enough of the books we admire and enjoy are getting the recognition they deserve.) That they were so enormously successful is no doubt because of luck, and hype, and the right people noticing and spreading the word, and a lot of other factors not related to the quality of the writing. Maybe the writer got lucky delivering that something at just the right moment when readers were craving it. Timing is important. And sometimes timing is just luck, pure and simple. But sometimes it's about being canny enough to know what readers are looking for and can't get enough of to satisfy them. Meanwhile, excellent books may fail because the timing is against them. (And yet may be discovered later in the writer's life time, or after the writer is dead, when the timing is right. Or that may never happen, and they will sink into undeserved obscurity.)
Sometimes what a book has that gives it that big push is originality, just at the time that readers are looking for something fresh (they aren't always). But breaking the rules does not always lead to originality -- as so many novice writers think -- in fact, I believe it rarely does, because a lot of the books that fail are breaking the rules in exactly the same way. And then even if the writer does attain true originality, the book may be (as Samuel Johnson once allegedly wrote) "both good and original. But the part that is good is not original, and the part that is original is not good."
As for hard work, more than likely it is going to improve your writing, and the longer you keep working hard the better your writing will be, thereby increasing your chances of being in the right place at the right time for luck to work in your favor. Persistence, is very, very important. If you write more than one very good book, then you increase your chances that one of them will grab the public's fancy. And that increases the chances that readers will suddenly have a burning interest in your books that didn't do well before. (Or at least that those books will be lauded after your death -- cold comfort, I know.)
But I've known writers who work very hard and still ... well, their writing isn't good and it's not improving. They seem to be incapable of absorbing the lessons that the rest of us learn. Maybe someday they'll have an epiphany and suddenly they will understand a great many things they are incapable of understanding now. That's not impossible. We all have smaller epiphanies along the way. That's part of how we all improve. And if they have that greater epiphany and become a great deal better (but perhaps still not outstandingly good), they may get lucky and write a book with enough of the something that a lot of readers are looking for at the time. But perhaps they will never have that moment where all becomes clear, and continue to work, and never get better at all. In which case, they'll never get that lucky break that only comes to those whose writing rises above a certain level.
So even hard work is no guarantee, if there is no talent at all. No book succeeds by virtue of one factor only: hard work, talent, originality, timing, luck, being canny about what people want, hype, etc. You need a combination, not of all of them, but more than one or two. But the only one you can absolutely control is how much work you do.