Context. N-methylformamide, CH 3 NHCHO, may be an important molecule for interstellar pre-biotic chemistry because it contains a peptide bond, which in terrestrial chemistry is responsible for linking amino acids in proteins. The rotational spectrum of the most stable trans conformer of N-methylformamide is complicated by strong torsion-rotation interaction due to the low barrier of the methyl torsion. For this reason, the theoretical description of the rotational spectrum of the trans conformer has up to now not been accurate enough to provide a firm basis for its interstellar detection. Aims. In this context, as a prerequisite for a successful interstellar detection, our goal is to improve the characterization of the rotational spectrum of N-methylformamide. Methods. We use two absorption spectrometers in Kharkiv and Lille to measure the rotational spectra over the frequency range 45-630 GHz. The analysis is carried out using the Rho-axis method and the RAM36 code. We search for N-methylformamide toward the hot molecular core Sagittarius (Sgr) B2(N2) using a spectral line survey carried out with the Atacama Large Millimeter/submillimeter Array (ALMA). The astronomical spectra are analyzed under the assumption of local thermodynamic equilibrium. The astronomical results are put into a broader astrochemical context with the help of a gas-grain chemical kinetics model. Results. The new laboratory data set for the trans conformer of N-methylformamide consists of 9469 distinct line frequencies with J ≤ 62, including the first assignment of the rotational spectra of the first and second excited torsional states. All these lines are fitted within experimental accuracy for the first time. Based on the reliable frequency predictions obtained in this study, we report the tentative detection of N-methylformamide towards Sgr B2(N2). We find N-methylformamide to be more than one order of magnitude less abundant than formamide (NH 2 CHO), a factor of two less abundant than the unsaturated molecule methyl isocyanate (CH 3 NCO), but only slightly less abundant than acetamide (CH 3 CONH 2 ). We also report the tentative detection of the 15 N isotopologue of formamide ( 15 NH 2 CHO) toward Sgr B2(N2). The chemical models indicate that the efficient formation of HNCO via NH + CO on grains is a necessary step in the achievement of the observed gas-phase abundance of CH 3 NCO. Production of CH 3 NHCHO may plausibly occur on grains either through the direct addition of functional-group radicals or through the hydrogenation of CH 3 NCO. Conclusions. Provided the detection of N-methylformamide is confirmed, the only slight underabundance of this molecule compared to its more stable structural isomer acetamide and the sensitivity of the model abundances to the chemical kinetics parameters suggest that the formation of these two molecules is controlled by kinetics rather than thermal equilibrium.