Packaging of genetic material inside a capsid is one of the major processes in the lifecycle of bacteriophages. To establish the basic principles of packing double-stranded DNA into a phage, we present a low-resolution model of bacteriophage varphi29 and report simulations of DNA packaging. The simulations show excellent agreement with available experimental data, including the forces of packaging and the average structures seen in cryo-electron microscopy. The conformation of DNA inside the bacteriophage is primarily determined by the shape of the capsid and the elastic properties of DNA, but the energetics of packaging are dominated by electrostatic repulsions and the large entropic penalty associated with DNA confinement. In this slightly elongated capsid, the DNA assumes a folded toroidal conformation, rather than a coaxial spool. The model can be used to study packaging of other bacteriophages with different shapes under a range of environmental conditions.