A giant automated weapon from outside the galaxy destroyed several solar systems and the crew of the USS Constellation before Kirk used the Constellation to destroy it.
In 2267 the Enterprise followed a path of destroyed solar systems and found the USS Constellation adrift and badly damaged. Its commander, Commodore Matt Decker, was alone aboard. He had beamed his crew to a nearby planet, and they had died when a huge machine broke the world apart. The machine was a planet killer, a robot weapon shaped like a long cone, built of solid neutronium and fueled by the planets it destroyed, apparently a doomsday device from another galaxy.
Once aboard the Enterprise, Decker used his rank to take command while Kirk was still on the Constellation and attacked the machine, nearly destroying the ship. Spock regained command, but Decker stole a shuttlecraft and flew it into the machine's mouth, dying in the attempt. The small explosion seemed to weaken the machine.
Kirk had the Constellation's impulse engines set to overload and steered the ship into the planet killer. Scott beamed him back at the last moment, and the explosion inside the machine left it dead. Kirk feared that other such weapons might exist.