Superconductivity often emerges in the proximity of, or in competition with, symmetry-breaking ground states such as antiferromagnetism or charge density waves(1-5) (CDW). A number of materials in the cuprate family, which includes the high transition-temperature (high-T-c) superconductors, show spin and charge density wave order(5-7). Thus a fundamental question is to what extent do these ordered states exist for compositions close to optimal for superconductivity. Here we use high-energy X-ray diffraction to show that a CDW develops at zero field in the normal state of superconducting YBa2Cu3O6.67 (T-c = 67 K). This sample has a hole doping of 0.12 per copper and a well-ordered oxygen chain superstructure(8). Below T-c, the application of a magnetic field suppresses superconductivity and enhances the CDW. Hence, the CDW and superconductivity in this typical high-T-c material are competing orders with similar energy scales, and the high-T-c superconductivity forms from a pre-existing CDW environment. Our results provide a mechanism for the formation of small Fermi surface pockets9, which explain the negative Hall and Seebeck effects(10,11) and the `T-c plateau'(12) in this material when underdoped.