Viral genomes are packaged into "procapsids" by powerful molecular motors. We report the crystal structure of the DNA packaging motor protein, gene product 17 (gp17), in bacteriophage T4. The structure consists of an N-terminal ATPase domain, which provides energy for compacting DNA, and a C-terminal nuclease domain, which terminates packaging. We show that another function of the C-terminal domain is to translocate the genome into the procapsid. The two domains are in close contact in the crystal structure, representing a "tensed state." A cryo-electron microscopy reconstruction of the T4 procapsid complexed with gp17 shows that the packaging motor is a pentamer and that the domains within each monomer are spatially separated, representing a "relaxed state." These structures suggest a mechanism, supported by mutational and other data, in which electrostatic forces drive the DNA packaging by alternating between tensed and relaxed states. Similar mechanisms may occur in other molecular motors.