Context. Ellerman bombs (EBs), observed in the photospheric wings of the Hα line, and UV bursts, observed in the transition region Si iv line, are both brightenings related to flux emergence regions and specifically to magnetic flux of opposite polarity that meet in the photosphere. These two reconnection-related phenomena, nominally formed far apart, occasionally occur in the same location and at the same time, thus challenging our understanding of reconnection and heating of the lower solar atmosphere. Aims. We consider the formation of an active region, including long fibrils and hot and dense coronal plasma. The emergence of a untwisted magnetic flux sheet, injected 2.5 Mm below the photosphere, is studied as it pierces the photosphere and interacts with the preexisting ambient field. Specifically, we aim to study whether EBs and UV bursts are generated as a result of such flux emergence and examine their physical relationship. Methods. The Bifrost radiative magnetohydrodynamics code was used to model flux emerging into a model atmosphere that contained a fairly strong ambient field, constraining the emerging field to a limited volume wherein multiple reconnection events occur as the field breaks through the photosphere and expands into the outer atmosphere. Synthetic spectra of the different reconnection events were computed using the 1.5D RH code and the fully 3D MULTI3D code. Results. The formation of UV bursts and EBs at intensities and with line profiles that are highly reminiscent of observed spectra are understood to be a result of the reconnection of emerging flux with itself in a long-lasting current sheet that extends over several scale heights through the chromosphere. Synthetic spectra in the Hα and Si iv 139.376 nm lines both show characteristics that are typical of the observations. These synthetic diagnostics suggest that there are no compelling reasons to assume that UV bursts occur in the photosphere. Instead, EBs and UV bursts are occasionally formed at opposite ends of a long current sheet that resides in an extended bubble of cool gas.