A measurement of the cross section for top quark-antiquark (t t ¯) pairs produced in association with a photon in proton-proton collisions at s=8 TeV is presented. The analysis uses data collected with the CMS detector at the LHC, corresponding to an integrated luminosity of 19.7 fb1. The signal is defined as the production of a t t ¯ pair in association with a photon having a transverse energy larger than 25 GeV and an absolute pseudorapidity smaller than 1.44. The measurement is performed in the fiducial phase space corresponding to the semileptonic decay chain of the t t ¯ pair, and the cross section is measured relative to the inclusive t t ¯ pair production cross section. The fiducial cross section for associated t t ¯ pair and photon production is found to be 127 ±27 (stat+syst) fb per semileptonic final state. The measured value is in agreement with the theoretical prediction.[Figure not available: see fulltext.].