“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.

Mr. Lawrence, who previously directed the hectic, obnoxious “Constantine” and many music videos, uses elaborate, computer-assisted means to create simple, striking effects. While “I Am Legend,” the latest in a series of film versions of a novel by Richard Matheson, fits comfortably within the conventions of the sci-fi horror genre — here come those zombies! — it mixes dread and suspense with contemplative, almost pastoral moods. And without taking itself too seriously, the movie, written by Akiva Goldsman and Mark Protosevich, does ponder some pretty deep questions about the collapse and persistence of human civilization.

An error has occurred. Please try again later.

You are already subscribed to this email.

Neville, a scientist and a soldier, constitutes a civilization of one. His daily routines are at once practical — he wants to find a cure for the virus that wiped everyone else out, and he needs to be home before sundown — and spiritual. Under the streets of the city and in its empty buildings are the infected, transformed by the virus into pale, hairless, light-allergic cannibals. “Social de-evolution appears to be complete,” Neville observes as he makes notes in his basement lab. And his habits are a way not only of protecting himself from the zombies, but also of maintaining the distinction between them and him.

The zombies, like the rabid dogs that are their companions, nonetheless display rudimentary pack behavior and are even able to set traps and make plans. Once they begin swarming, “I Am Legend” inevitably loses some of its haunting originality, since they look a lot like the monsters in “28 Days Later” (and its sequel, “28 Weeks Later”). They also represent a less compelling application of computer-generated imagery than all those empty avenues and silent buildings.

And in its last section “I Am Legend” reverts to generic type, with chases and explosions and a redemptive softening of its bleak premise. The presence of the lovely Brazilian actress Alice Braga does seem promising; if she and Mr. Smith were to reboot the species together, Humanity 2.0 would be quite a bit sexier than the present version, as well as friendlier. But really the movie is best when its hero is on his own, and Mr. Smith, walking in the footsteps of Vincent Price and Charlton Heston, who played earlier versions of the Robert Neville character, outdoes both of them. There is something graceful and effortless about this performance, which not only shows what it might feel like to be the last man on earth, but also demonstrates what it is to be a movie star.