A thin film technology compatible with multilayer device fabrication is critical for exploring the potential of the 39-K superconductor magnesium diboride for superconducting electronics. Using a Hybrid Physical-Chemical Vapor Deposition (HPCVD) process, it is shown that the high Mg vapor pressure necessary to keep the MgB$_2$ phase thermodynamically stable can be achieved for the {it in situ} growth of MgB$_2$ thin films. The films grow epitaxially on (0001) sapphire and (0001) 4H-SiC substrates and show a bulk-like $T_c$ of 39 K, a $J_c$(4.2K) of $1.2 times 10^7$ A/cm$^2$ in zero field, and a $H_{c2}(0)$ of 29.2 T in parallel magnetic field. The surface is smooth with a root-mean-square roughness of 2.5 nm for MgB$_2$ films on SiC. This deposition method opens tremendous opportunities for superconducting electronics using MgB$_2$.