Femtosecond X-ray diffraction and ab initio density functional theory calculations are used to determine the crystal structure of YBa2Cu3O6.5 undergoing optically driven, nonlinear lattice excitation above the transition temperature of 52 kelvin, under which conditions the electronic structure of the material changes in such a way as to favour superconductivity. Andrea Cavalleri and colleagues use femtosecond X-ray diffraction measurements and ab initio density functional theory calculations to determine the crystal structure of YBa2Cu3O6+x undergoing optically driven, nonlinear lattice excitation at 100 kelvin. In this exotic non-equilibrium state, the electronic structure of the material changes in such a way as to favour superconductivity. The results reveal that in the driven state the superconducting planes are displaced closer and away from one another in a staggered manner, explaining how superconducting coupling can be enhanced or reduced, inside and between the bilayers. Terahertz-frequency optical pulses can resonantly drive selected vibrational modes in solids and deform their crystal structures1,2,3. In complex oxides, this method has been used to melt electronic order4,5,6, drive insulator-to-metal transitions7 and induce superconductivity8. Strikingly, coherent interlayer transport strongly reminiscent of superconductivity can be transiently induced up to room temperature (300 kelvin) in YBa2Cu3O6+x (refs 9, 10). Here we report the crystal structure of this exotic non-equilibrium state, determined by femtosecond X-ray diffraction and ab initio density functional theory calculations. We find that nonlinear lattice excitation in normal-state YBa2Cu3O6+x at above the transition temperature of 52 kelvin causes a simultaneous increase and decrease in the Cu–O2 intra-bilayer and, respectively, inter-bilayer distances, accompanied by anisotropic changes in the in-plane O–Cu–O bond buckling. Density functional theory calculations indicate that these motions cause drastic changes in the electronic structure. Among these, the enhancement in the character of the in-plane electronic structure is likely to favour superconductivity.