Tests of Einstein's general theory of relativity have mostly been carried out in weak gravitational fields where the space-time curvature effects are first-order deviations from Newton's theory. Binary pulsars provide a means of probing the strong gravitational field around a neutron star, but strong-field effects may be best tested in systems containing black holes. Here we report such a test in a close binary system of two candidate black holes in the quasar OJ287. This quasar shows quasi-periodic optical outbursts at 12-year intervals, with two outburst peaks per interval. The latest outburst occurred in September 2007, within a day of the time predicted by the binary black-hole model and general relativity. The observations confirm the binary nature of the system and also provide evidence for the loss of orbital energy in agreement (within 10 per cent) with the emission of gravitational waves from the system. In the absence of gravitational wave emission the outburst would have happened 20 days later.