Starfleet Command dispatches the Enterprise to investigate the presence of an eight-hundred thousand kilometer-wide cosmic cloud, a bizarre mixture of matter and energy that has suddenly appeared from beyond the boundaries of the Milky Way galaxy, and which may threaten the existence of Mantilles, a Federation colony of 82-million people located in the Pallas XIV system, near the galactic rim.

The Enterprise intercepts the cloud near Alondra, one of the system's uninhabited outer worlds, where the crew observes the cloud devouring the entire planet it adopts a direct heading for Mantilles. With the cloud only hours away from the densely populated colony world, Captain Kirk contacts the planetary governor, former Starfleet Commodore Robert Wesley, with a warning about the rapidly approaching danger. Wesley, an old friend of Kirk's, is grateful for the opportunity to save at least some of his constituents, and immediately begins trying to evacuate some five thousand of the colony's children.

Taking the Enterprise toward the cloud, Kirk is unable to prevent his ship from being drawn into the cloud's vast interior, where the cloud attempts to destroy the starship with antimatter structures that drain the vessel's power and shields to hazardously low levels. Realizing that the Enterprise is in the process of being "digested? within what amounts to a giant intestinal tract within the cloud, Spock determines that the cloud is a living entity that possesses a brain, which Kirk gains the ability to destroy after Chief Engineer Scott succeeds in using the cloud creature's "antimatter villi? to recharge the Enterprise's engines. Despite his reticence about killing an intelligent creature, Kirk can see little alternative to doing just that. Fortunately, Spock soon contacts the cloud entity's consciousness via the Vulcan mind-meld. With mere seconds to spare before the cloud devours Mantilles, Spock informs the entity that it is about to destroy many millions of intelligent beings. Previously unaware of this consequence of its actions, the cloud agrees to leave Mantilles and heads home to its point of origin outside the galaxy. Afterward, an awed Spock comments on the wonders of the universe that he experienced during his brief mind-meld with the vast cosmic entity.