Context. Previously unremarkable, the extragalactic radio source GB 1310+487 showed a γ-ray flare on 2009 November 18, reaching a daily flux of ∼10 −6 photons cm −2 s −1 at energies E > 100 MeV and became one of the brightest GeV sources for about two weeks. Its optical spectrum shows strong forbidden-line emission while lacking broad permitted lines, which is not typical for a blazar. Instead, the spectrum resembles those of narrow emission-line galaxies. Aims. We investigate changes in the object's radio-to-GeV spectral energy distribution (SED) during and after the prominent γ-ray flare with the aim of determining the nature of the object and of constraining the origin of the variable high-energy emission. Methods. The data collected by the Fermi and AGILE satellites at γ-ray energies; Swift at X-ray and ultraviolet (UV); the Kanata, NOT, and Keck telescopes at optical; OAGH and WISE at infrared (IR); and IRAM 30 m, OVRO 40 m, Effelsberg 100 m, RATAN-600, and VLBA at radio are analyzed together to trace the SED evolution on timescales of months. Results. The γ-ray/radio-loud narrow-line active galactic nucleus (AGN) is located at redshift z = 0.638. It shines through an unrelated foreground galaxy at z = 0.500. The AGN light is probably amplified by gravitational lensing. The AGN SED shows a two-humped structure typical of blazars and γ-ray-loud narrow-line Seyfert 1 galaxies, with the high-energy (inverse-Compton) emission dominating by more than an order of magnitude over the low-energy (synchrotron) emission during γ-ray flares. The difference between the two SED humps is smaller during the low-activity state. Fermi observations reveal a strong correlation between the γ-ray flux and spectral index, with the hardest spectrum observed during the brightest γ-ray state. The γ-ray flares occurred before and during a slow rising trend in the radio, but no direct association between γ-ray and radio flares could be established. Conclusions. If the γ-ray flux is a mixture of synchrotron self-Compton and external Compton emission, the observed GeV spectral variability may result from varying relative contributions of these two emission components. This explanation fits the observed changes in the overall IR to γ-ray SED.