This is the way it’s supposed to end. The title “I Am Legend” refers to
Neville realizing that the infected are in fact the future of humanity,
and that by killing them, though his intentions were pure, he has
become the thing of legends, the mythical creature that preys on humans
and causes them fear. While the theatrical ending pleased audiences
more, this is the ending that Richard Matheson intended and the only one
that makes sense with the title.