We present a theoretical and experimental study of viscous flows injected into a porous medium that is confined vertically by horizontal impermeable boundaries and filled with an ambient fluid of different density and viscosity. General three-dimensional equations describing such flows are developed, showing that the dynamics can be affected by two separate contributions: spreading due to gradients in hydrostatic pressure, and that due to the pressure drop introduced by the injection. In the illustrative case of a two-dimensional injection of fluid at a constant volumetric rate, the injected fluid initially forms a viscous gravity current insensitive both to the depth of the medium and to the viscosity of the ambient fluid. Beyond a characteristic time scale, the dynamics transition to being dominated by the injection pressure, and the injected fluid eventually intersects the second boundary to form a second moving contact line. Three different late-time asymptotic regimes can emerge, depending on whether the viscosity of the injected fluid is less than, equal to or greater than that of the ambient fluid. With a less viscous injection, the flow undergoes a slow decay towards a similarity solution in which the two contact lines extend linearly in time with differing prefactors. Perturbations from this long-term state are shown to decay algebraically with time. Equal viscosities result in both contact lines approaching the same leading-order asymptotic position but with a first-order correction to the distance between them that expands as t 1/2 due to gravitational spreading. For a more viscous injection, the distance between the contact lines approaches a constant value, with perturbations decaying exponentially. Data from a new series of laboratory experiments confirm these theoretical predictions.