Well, what do you think about that ending? Totally not what you were expecting, right? We can break this ending down into a few movements to help clarify how it works.
First, there's the part where all the Martians are dead of infection. There are a bunch of clues in the book that foreshadow either that the Martians can be killed or that it's going to be microorganisms that do the killing. For instance, the first line of the book notes that the Martians are "as mortal" as man, so we know they can be killed from the very beginning. The narrator later notes that the Martians have no microorganisms (2.2.22), and that the red weed died very quickly from bacterial infection (2.6.6). The death of the Martians is one of those shocking surprises that, when you look back on it, you might kick yourself for not figuring out earlier.
That's only part of the ending, though it is the part that the movie versions end on: "The Martians are dead from infection. Let's party!" However, in the book, after the Martians have died out, we get to see what's going on with the Earth, and it's a strange mixture of optimistic and pessimistic moments. For one optimistic moment, the narrator is taken in and cared for by total strangers. We could compare that to almost any crowd scene earlier in the book where people tend to trample total strangers. Once the invasion is over, people seem much nicer to each other. That's true for the whole world. Every country helps Britain after the invasion, and there's a sense that we're all in this together. Let's also not forget that after thinking that his wife is dead for much of the book, the narrator is finally reunited with her at the end. This is a happy ending, right?
Not so fast. Most of the happy stuff happens in the short Book 2. Chapter 9, so let's move on to Chapter 10, where things are less rosy. Yes, there's a sense of humanity all being part of one big family, which is so sweet it gives us cavities. Sure, we're all in it together – but what is "it"? According to the narrator's final thoughts on the subject, "it" seems to be the endless competition for life.
Humans have survived the Martian invasion, but what happens when our own planet starts to die and is unable to support life? According to the narrator, we might just head off to start a war on Venus. If you thought this was the end of war, you'd be wrong. What's more, we might lose that war in the future, says the narrator. Hmm. Now we're feeling less optimistic.
To top it all off, the narrator tells us that he sometimes has visions of the destruction of the world, six years after the invasion. (Wells wouldn't have thought of it this way, but it sounds kind of like the narrator is suffering from Post-Traumatic Stress Disorder.) So, even if the Martian invasion had some good effects (like our successful research into Martian flying technology), we have to recognize that it's kind of a mixed bag. The narrator has both: a) visions of humanity's successful conquest of space, and b) flashbacks to the destruction of the Martian invasion.
Maybe the mixed nature of the ending can be expressed by the final line, which sounds very ambiguous to us: "And strangest of all is it to hold my wife's hand again, and to think that I have counted her, and that she has counted me, among the dead" (2.10.13). It sounds sort of happy, like a joyful surprise ("I thought you were dead, but you're not. Yay!"), but what's missing is any note of actual joy or happiness in it. Honestly, he just doesn't sound happy to be married sometimes.
Finally, one thing to note about the last chapter is that it seems to parallel the very first one. That is, both the first and the last chapters start with some bird's-eye view of the situation (how the Earth is doing now) and then moves into the narrator's own story. Even though the content of the story is ambiguous and somewhat open-ended, there is a way in which this ending seems like a fitting way to close the story.