Jet-associated deuteron production in pp collisions at s=13 TeV and p-Pb collisions at sNN=5.02 TeV is studied in the coalescence model by using the phase-space information of proton and neutron pairs from a multiphase transport (AMPT) model at the kinetic freezeout. In the low transverse momentum (pT) region pT/A<1.5 GeV/c, where A is the mass number of a nucleus, the in-jet coalescence factor B2In-jet for deuteron production, given by the ratio of the in-jet deuteron number to the square of the in-jet proton number, is found to be larger than the coalescence factor B2 in the medium perpendicular to the jet by a factor of about 10 in pp collisions and of 25 in p−Pb collisions, which are consistent with the ALICE measurements at the LHC. Such large low-momentum enhancements mainly come from coalescence of nucleons inside the jet with the medium nucleons. Coalescence of nucleons inside the jet dominates deuteron production only at the higher pT region of pT/A≳4 GeV/c, where both the yield ratio d/p of deuteron to proton numbers and the B2 are also significantly larger in the jet direction than in the direction perpendicular to the jet due to the strong collinear correlation among particles produced from jet fragmentation. Studying jet-associated deuteron production in relativistic nuclear collisions thus opens up a new window to probe the phase-space structure of nucleons inside jets.