Generalizing the well-known Shafarevich hyperbolicity conjecture, it has been conjectured by Viehweg that a quasi-projective manifold that admits a generically finite morphism to the moduli stack of canonically polarized varieties is necessarily of log general type. Given a quasi-projective threefold $Y^\circ$ that admits a nonconstant map to the moduli stack, we employ extension properties of logarithmic pluriforms to establish a strong relationship between the moduli map and the minimal model program of $Y^\circ$ : in all relevant cases the minimal model program leads to a fiber space whose fibration factors the moduli map. A much-refined affirmative answer to Viehweg's conjecture for families over threefolds follows as a corollary. For families over surfaces, the moduli map can often be described quite explicitly. Slightly weaker results are obtained for families of varieties with trivial or more generally semiample canonical bundle.