Sources of high-energy photons have important applications in almost all areas of research. However, the photon flux and intensity of existing sources is strongly limited for photon energies above a few hundred keV. Here we show that a high-current ultrarelativistic electron beam interacting with multiple submicrometer-thick conducting foils can undergo strong self-focusing accompanied by efficient emission of gamma-ray synchrotron photons. Physically, self-focusing and high-energy photon emission originate from the beam interaction with the near-field transition radiation accompanying the beam-foil collision. This near field radiation is of amplitude comparable with the beam self-field, and can be strong enough that a single emitted photon can carry away a significant fraction of the emitting electron energy. After beam collision with multiple foils, femtosecond collimated electron and photon beams with number density exceeding that of a solid are obtained. The relative simplicity, unique properties, and high efficiency of this gamma-ray source open up new opportunities for both applied and fundamental research including laserless investigations of strong-field QED processes with a single electron beam.