Larry Daley is a divorced man who has been unable to keep a stable job and has failed at many business ventures, including being an inventor. His invention of "the Snapper", which does exactly what the clapper does, has failed because there is a significant number of people who cannot snap, and therefore, cannot use it. His former wife believes that he is a bad example to their ten-year-old son Nick, and Larry fears that Nick respects his future stepfather, bond trader Don, more than him.
Cecil Fredricks, an elderly night security guard about to retire from the American Museum of Natural History, hires Larry despite his unpromising résumé. The museum, which is rapidly losing money, plans to replace Cecil and two colleagues Gus and Reginald with one guard. Cecil gives Larry an instruction booklet on how to handle museum security, and advises Larry to leave some of the lights on and warns him not to let anything "in...or out".
Once night falls, Larry discovers that the exhibits come to life, including a playful Tyrannosaurus skeleton nicknamed "Rexy" who behaves like a dog; a mischievous capuchin monkey named Dexter which steals Larry's keys and tears up his instruction booklet; rival miniature civilizations led by Old West cowboy Jedediah and Roman general Octavius; limb-ripping Attila the Hun; an Easter Island Moai obsessed with "gum-gum" who addresses Larry as Dum-Dum; and a wax model of Theodore Roosevelt.
Roosevelt explains that since an Egyptian artifact—the Golden Tablet of Pharaoh Ahkmenrah—came to the museum in 1952, all of the exhibits come to life each night. If the exhibits are outside the museum during sunrise, they turn to dust. Roosevelt helps Larry by restoring order, but only for one night. Larry quits the next morning, saying to the three guards he doesn't want a job that is life-threatening. However, he sees Nick coming to see him at work the next morning, where Larry offers Nick a tour of the museum. After seeing Nick's interest in his job, Larry decides to remain as a night guard.
When Larry tells Cecil about how Dexter tore up his instructions, Cecil advises him to study history to prepare himself for his nightly duties. He also learns history from a museum docent Rebecca Hutman, who is writing a dissertation on Sacagawea, but does not feel she knows enough about her subject.
The next night, Larry uses what he has learned to better control the exhibits. However, things go wrong anyway and four Neanderthals set fire to a display and some other things. One of the Neanderthal turns to dust when he leaves the museum at dawn. The next morning, museum director Dr. McPhee almost fires Larry after what happened to the Neanderthal exhibit. He offers Rebecca a meeting with Sacagawea, but she believes that he is mocking her and the museum.
Larry brings Nick to the museum to show him the exhibits, but none of them are alive. They find Cecil, Gus, and Reginald stealing the tablet and other valuable objects. Like the exhibits, the guards receive enhanced vitality from the artifact; wishing to retain their youth, health and to fund their retirements, the three plan to frame Larry for the thefts. They have also disabled the tablet to stop the exhibits from interfering. Nick reactivates the artifact, but Cecil locks him and his father in the Egyptian room and flees with the tablet. Larry releases Ahkmenrah's mummy from his sarcophagus. The pharaoh speaks English from many years as an exhibit at Cambridge, and helps Larry and Nick escape. The three find the other exhibits fighting; Larry confronts Attila, realizing his behavior came from being hurt a long time ago, and convinces them to work together.
The exhibits capture Gus and Reginald without difficulty, but Cecil escapes by stagecoach with Larry, Nick, Ahkmenrah, Jed, Octavius, Rexy, and Atilla the Hun in pursuit in Central Park, where they stop him and regain the tablet. Jed and Octavius are presumably killed when their remote-controlled Hummer crashes, but they somehow survive. Rebecca sees the exhibits return to the museum before sunrise and realizes that Larry was telling the truth; he introduces her to Sacagawea.
Dr. McPhee fires Larry again after seeing news reports of the strange events around the museum – such as cave paintings in the museum's subway station, dinosaur footprints in Central Park, and cavemen sightings. However, upon seeing how much these events raised attendance, he thinks better of it and gives Larry his job back. Larry, Nick, and the exhibits celebrate the following night.
During the credits, it was shown that Cecil, Gus and Reginald weren't handed over to the authorities and are now working as janitors at the museum.