Brainiac captures six members of the seven "Emotional Spectrum" Lantern Corps, and heads to Earth to abduct the final one: Hal Jordan, the Green Lantern. In Gotham City, Batman and Robin pursue Killer Croc, who has stolen a map of the sewer system underneath the Hall of Justice, but he escapes and reunites with his accomplices: the Joker, Cheetah, Firefly, and Solomon Grundy. Meanwhile, Cyborg completes the "Slideways Teleporter" linking the Hall of Justice to the Justice League Watchtower and sends Green Lantern through it to meet with Martian Manhunter as a trial run, leaving the portal open.
While observing Brainiac's approaching spaceship from the Batcave, Batman is exposed to its mind-control rays and goes berserk, until Robin talks him out of the trance with a heartfelt speech; however, Batman is convinced that he was awoken from the trance by the Batmobile's defense system, which had electrocuted him. Meanwhile, the villains use the stolen map to infiltrate the Hall of Justice undetected, where they meet with their benefactor, Lex Luthor, who posed as Hawkman to gain access. The group then travels to the Watchtower through the Slideways Teleporter, intending to use its fusion cannon to hold the Earth at ransom until Luthor is elected "President of Earth", but unwittingly trigger the Watchtower's alarm. Martian Manhunter informs the Justice League (sans Green Lantern, who was captured while investigating Brainiac's ship) and together they defeat the villains. However, Brainiac arrives and reveals his intentions to the group: to shrink the Earth with his ray, powered by the combined energies of the Lantern Corps' power rings, and add it to his collection of miniature planets.
While Superman flies into space to stop the shrink ray from reaching Earth, the remaining heroes form an uneasy alliance with the villains (who want to save the Earth so that they might conquer it afterward) and they infiltrate Brainiac's ship together, only to get captured. Robin, who is protected from Brainiac's mind-control rays by Doctor Fate's helmet, frees the others, while Superman punches his way through the shrink ray and into the ship, damaging the main computer and causing the Lanterns to be teleported back to their home planets. Deeming his ship doomed, Brainiac escapes in a smaller spacecraft to Earth (which has been only partially shrunk), and Batman, Superman, and Wonder Woman pursue him. After shrinking Paris, London, and Pisa, Brainiac attacks Gotham, but is defeated by the combined efforts of the heroes and villains, and trapped within his own ship.
To restore Earth to its original size, Superman suggests recreating the shrink ray using the crystals at the Fortress of Solitude, shards of the destroyed ray which Robin retrieved, and the energy of each Lantern's power ring. While Superman goes after the crystals and most of the villains are locked up, the other heroes and Solomon Grundy split into two groups to recruit Star Sapphire, Indigo-1, and Saint Walker to help, and confront Atrocitus, Larfleeze, and Sinestro to provoke them into following them to Earth. During a battle between the positive and negative emotions Lanterns at the Fortress, the heroes manage to harvest the combined energies of their rings and use them to power their replica of the shrink ray, using it to restore Earth to its original size; as a side effect, the Lanterns are sent back to their homeworlds once again. Meanwhile, Brainiac escapes and regains control of his ship, using it to mind-control Superman, who had grown to gigantic proportions as a result of holding the shrink ray during its activation. After all attempts to free Superman from Brainiac's control fail, Batman realizes that it was Robin's speech that helped him recover from his trance when he was exposed to the same mind-control rays, and holds a similar speech. Awakening from the trance, Superman destroys Brainiac's ship, shrinking himself back to normal proportions and the latter to a minuscule size in the process.
Later, the Justice League restore all the shrunken cities collected by Brainiac to their original locations, and capture the Legion of Doom, who escaped and took over the White House while the heroes were distracted by Brainiac's attack. Luthor and the Joker are imprisoned in the same cell as the shrunken Brainiac, but accidentally break the bottle he was held in, causing Brainiac to return to normal proportions.
In the mid- and post-credits scenes, Sinestro vows revenge against the Justice League, only to bump into Wonder Woman's invisible jet; a new group of heroes arrive at the Watchtower through the Slideways Teleporter; and Hawkman, who was locked up in a cage underneath the Hall of Justice by Luthor, unsuccessfully tries to escape.