“Not if you were the last man on earth!” Plenty of guys have heard that line at some point in their lives, but it’s unlikely that Will Smith is one. His irresistible charm has been proved, above all, by his ability to attract audiences to bad movies like “Hitch” and “Wild Wild West,” as well as to better ones like “Ali” and “The Pursuit of Happyness.” In spite of its third-act collapse into obviousness and sentimentality, “I Am Legend”  in which Mr. Smith plays somebody with every reason to believe that he really is the last man on earth  is among the better ones.

And this star, whose amiability makes him easy to underestimate as an actor, deserves his share of the credit. There are not many performers who can make themselves interesting in isolation, without human supporting players. Tom Hanks did it in “Cast Away,” with only a volleyball as his buddy, foil and straight man. Mr. Smith has a few more companions, including an expressive German shepherd, some department store mannequins and a high-powered rifle. (There are also some flesh-eating, virus-crazed zombies, about which more in a moment.) But it is the charismatic force of his personality that makes his character’s radical solitude scary and fascinating, as well as strangely appealing.

In this Mr. Smith is helped, and to some degree upstaged, by the island of Manhattan, which the movie’s director, Francis Lawrence, has turned into a post-apocalyptic wilderness. Three years after an epidemic has caused the evacuation and quarantine of New York City, Robert Neville (Mr. Smith) is its sole diurnal human resident, and he spends his days roaming its desolate neighborhoods, at once wary and carefree. The streetscapes he wanders through will be familiar to any visitor or resident, but the way Mr. Lawrence and his team of digital-effects artists have distressed and depopulated New York is downright uncanny. Weeds poke up through the streets, which are piled with abandoned cars, and a slow, visible process of decay has set in.

A nightmare, of course, but not without its enchantments. In some ways Neville, dwelling in a highly developed urban space that is also a wilderness, experiences the best of both worlds. From his home base in the elegant Washington Square town house he was lucky enough to own (on a government employee’s salary) before the big die-off, he makes daylight forays that are like an adventure-tourist fantasy. He does a little deer hunting on Park Avenue and some indoor fishing at the Temple of Dendur, picks fresh corn in Central Park and smacks golf balls across the Hudson from the deck of the aircraft carrier Intrepid.