See also the Doomsday Machine Q&A, the reason why this is here.
From outside the galaxy, a conical weapon-ship appears, and enters the galaxy. Miles in length, protected by a solid neutronium hull and a powerful energy dampening field, the device is armed with an antiproton beam capable of chopping planets to rubble.
The weapon-ship is an automated device, designed as a planet-killer. It is intended to cut apart entire worlds and consume some of the material, fueling its total conversion drive. Several systems are destroyed in this manner as the device cuts a path that will carry it through some of the most populous worlds of the Federation.
The Constitution Class Starship USS Constellation, NCC-1017, commanded by Commodore Matthew Decker, finds some of these destroyed star systems. However, heavy subspace interference prevents the ship from contacting Starfleet to advise. The ship continues to investigate, eventually coming up on system L-374, near the Rigel system. There, they note that the fourth planet is in the process of breaking up, and approach.
The Constellation finds the planet-killer in the process of chopping the fourth planet to bits. Their approach, however, brings them into the defensive sphere of the device, and the ship comes under attack. The deflector shields, already strained due to the dampening field, are quickly overwhelmed, and soon the planet-killer's weaponry begins goring holes into the ship, melting and scorching the hull.
Decker and the Constellation attempt to escape toward the inner system, but the damage is done. The ship's bridge is uninhabitable, the generators are damaged, the phasers exhausted and useless, the impulse controls are burned out, and the starship's antimatter supply has been rendered inert. She's operating on reserve energy banks only. Unable to escape, unable to fight, and unable to call for help, the Constellation is a sitting duck for the approaching weapon-ship.
Worse yet, the life support systems are barely operable, and the air filtration system is down. In short, the ship was nothing more than a target, and one which could only barely sustain her crew, if at all. Decker thus gives the order to abandon ship, and the 400 crewmembers are beamed to the relative safety of the third planet of L-374. Commodore Decker remains behind.
Suddenly the weapon-ship is upon him, attacking the Constellation once again. The transporters are destroyed, and the ship adrift. But to Decker's horror, the device loses interest in the wrecked Constellation, and instead takes advantage of its position near the third planet to begin that world's disassembly. His crew calls for beam-up, but it's too late . . . the transporters are gone, the ship is immobilized, and all Decker can do is watch as the planet to which he sent his crew for refuge is destroyed beneath their feet.
Unbeknownst to Decker, the USS Enterprise was close enough to pick up the Constellation's weak, badly-garbled distress call. As the Enterprise travels toward the source of the call, they also discover destroyed solar systems. Eventually, the ship reaches L-374, finding that only the two inner planets of the system remain. Locating the Constellation via her disaster beacon, Kirk and a landing party board the ship, finding a distraught Decker and assessing the damage to the ship. Kirk prepares to take the Constellation in tow.
As McCoy and Decker beam over, however, the weapon-ship approaches. Kirk orders the Enterprise to beam the teams from Constellation aboard, but the device attacks the Enterprise, knocking out the transporter and damaging the comm systems. The Enterprise escapes, eventually getting outside the machine's defensive sphere, but before the ship can circle back to pick up the crewmen on the Constellation, Decker assumes command. The loss of his crew having driven him mad, Decker attacks the weapon-ship, engaging in a phaser barrage at point-blank range. But because of the neutronium hull, the phaser fire simply bounces off, and because of the machine's field, the ship's deflector shields strain to the limit even when the machine isn't firing.
Meanwhile, Kirk and the engineering team are able to restore severely limited impulse power, sensors, and even a phaser bank on the Constellation. Thus, when Decker's futile attack has resulted in shield failure, hull breaches, generator failures, and the loss of warp power aboard the Enterprise, and with the weapon-ship tractoring the Enterprise into its giant maw, Kirk is able to use the Constellation as a distraction. The Constellation is barely mobile, nearly impossible to control, and of limited combat utility, but its motion and weapons fire is sufficient to draw the planet-killer's attention away from the Enterprise. Decker then returns the favor, drawing the device's attention back toward the Enterprise and leading it away from the Constellation.
Communication is restored between the two Starfleet vessels, and Kirk orders Decker relieved. Spock takes command, ordering Decker to Sickbay. But, Decker overwhelms the security guard escorting him, and soon steals a shuttlecraft. Despite the entreaties of Kirk and Spock, Decker pilots the shuttle on a suicide run into the belly of the beast.
What is at first thought to be a senseless death becomes the key to destroying the Doomsday Machine. The explosion of the shuttlecraft produces a minute power drop in the device. Kirk has the damage control teams beamed back to the ship, and orders Scotty to rig the impulse engines, now capable of almost one-third impulse, to explode at Kirk's command. His plan is to use the impulse engines, each capable of generating a 97.835 megaton explosion when overloaded, to try to destroy the planet-killer from the inside. Scotty sets the 30-second delay and, per Kirk's order, beams to the Enterprise. Kirk approaches the planet-killer at over 50 kilometers per second relative speed, then within 15 seconds slows his approach to approximately 10km/sec. Kirk thereby pilots the Constellation straight into the maw of the weapon-ship, the half-operable transporter beaming him off at the last moment before the detonation.
The blast completely deactivates the Doomsday Machine, rendering it inert.