We present upper limits on the production of heavy neutral leptons (HNLs) decaying to $\mu \pi$ pairs using data collected with the MicroBooNE liquid-argon time projection chamber (TPC) operating at Fermilab. This search is the first of its kind performed in a liquid-argon TPC. We use data collected in 2017 and 2018 corresponding to an exposure of $2.0 \times 10^{20}$ protons on target from the Fermilab Booster Neutrino Beam, which produces mainly muon neutrinos with an average energy of $\approx 800$ MeV. HNLs with higher mass are expected to have a longer time-of-flight to the liquid-argon TPC than Standard Model neutrinos. The data are therefore recorded with a dedicated trigger configured to detect HNL decays that occur after the neutrino spill reaches the detector. We set upper limits at the $90\%$ confidence level on the element $\lvert U_{\mu4}\rvert^2$ of the extended PMNS mixing matrix in the range $\lvert U_{\mu4}\rvert^2<(6.6$-$0.9)\times 10^{-7}$ for Dirac HNLs and $\lvert U_{\mu4}\rvert^2<(4.7$-$0.7)\times 10^{-7}$ for Majorana HNLs, assuming HNL masses between $260$ and $385$ MeV and $\lvert U_{e 4}\rvert^2 = \lvert U_{\tau 4}\rvert^2 = 0$. Comment: 11 pages, 9 figures. Final accepted version by Phys. Rev. D, minor textual changes