Dielectric materials, which store energy electrostatically, are ubiquitous in advanced electronics and electric power systems. Compared to their ceramic counterparts, polymer dielectrics have higher breakdown strengths and greater reliability, are scalable, lightweight and can be shaped into intricate configurations, and are therefore an ideal choice for many power electronics, power conditioning, and pulsed power applications. However, polymer dielectrics are limited to relatively low working temperatures, and thus fail to meet the rising demand for electricity under the extreme conditions present in applications such as hybrid and electric vehicles, aerospace power electronics, and underground oil and gas exploration. Here we describe crosslinked polymer nanocomposites that contain boron nitride nanosheets, the dielectric properties of which are stable over a broad temperature and frequency range. The nanocomposites have outstanding high-voltage capacitive energy storage capabilities at record temperatures (a Weibull breakdown strength of 403 megavolts per metre and a discharged energy density of 1.8 joules per cubic centimetre at 250 degrees Celsius). Their electrical conduction is several orders of magnitude lower than that of existing polymers and their high operating temperatures are attributed to greatly improved thermal conductivity, owing to the presence of the boron nitride nanosheets, which improve heat dissipation compared to pristine polymers (which are inherently susceptible to thermal runaway). Moreover, the polymer nanocomposites are lightweight, photopatternable and mechanically flexible, and have been demonstrated to preserve excellent dielectric and capacitive performance after intensive bending cycles. These findings enable broader applications of organic materials in high-temperature electronics and energy storage devices.