Context. In recent years, organic molecules of increasing complexity have been found toward the prolific Galactic center source Sagittarius B2. Aims. We wish to explore the degree of complexity that the interstellar chemistry can reach in star-forming regions. Methods. We carried out a complete line survey of the hot cores Sgr B2(N) and (M) with the IRAM 30 m telescope in the 3 mm range, plus partial surveys at 2 and 1.3 mm. We analyzed this spectral survey in the local thermodynamical equilibrium approximation. We modeled the emission of all known molecules simultaneously, which allows us to search for less abundant, more complex molecules. We compared the derived column densities with the predictions of a coupled gas-phase and grain-surface chemical code.Results. We report the first detection in space of ethyl formate (C 2 H 5 OCHO) and n-propyl cyanide (C 3 H 7 CN) toward Sgr B2(N). The detection of n-propyl cyanide is based on refined spectroscopic parameters derived from combined analyses of available laboratory spectroscopic data. For each molecule, we identified spectral features at the predicted frequencies having intensities compatible with a unique rotation temperature. For an assumed source size of 3 , our modeling yields a column density of 5.4 × 10 16 cm −2 , a temperature of 100 K, and a linewidth of 7 km s −1 for ethyl formate. n-Propyl cyanide is detected with two velocity components having column densities of 1.5 × 10 16 cm −2 and 6.6 × 10 15 cm −2 , respectively, for a source size of 3 , a temperature of 150 K, and a linewidth of 7 km s −1 . The abundances of ethyl formate and n-propyl cyanide relative to H 2 are estimated to be 3.6 × 10 −9 and 1.0 × 10 −9 , respectively. We derived column density ratios of 0.8/15/1 for the related species t-HCOOH/CH 3 OCHO/C 2 H 5 OCHO and 108/80/1 for CH 3 CN/C 2 H 5 CN/C 3 H 7 CN. Our chemical modeling reproduces these ratios reasonably well. It suggests that the sequential, piecewise construction of ethyl and n-propyl cyanide from their constituent functional groups on the grain surfaces is their most likely formation route. Ethyl formate is primarily formed on the grains by adding CH 3 to functional-group radicals derived from methyl formate, although ethanol may also be a precursor. Conclusions. The detection in Sgr B2(N) of the next stage of complexity in two classes of complex molecule, esters and alkyl cyanides, suggests that greater complexity in other classes of molecule may be present in the interstellar medium.