Superconductivity often emerges in the proximity of, or in competition with, symmetry-breaking ground states such as antiferromagnetism or charge density waves (CDW). A number of materials in the cuprate family, which includes the high transition-temperature (high-Tc) superconductors, show spin and charge density wave order. 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 (Tc= 67 K). This sample has a hole doping of 0.12 per copper and a well-ordered oxygen chain superstructure. Below Tc, the application of a magnetic field suppresses superconductivity and enhances the CDW. Hence, the CDW and superconductivity in this typical high-Tc material are competing orders with similar energy scales, and the high-Tc superconductivity forms from a pre-existing CDW environment. Our results provide a mechanism for the formation of small Fermi surface pockets, which explain the negative Hall and Seebeck effects and the ‘Tc plateau’ in this material when underdoped.