The reactions of atomic nitrogen in its first electronically excited state, N(2D), with acetonitrile (CH3CN) and cyanoacetylene (HC3N) have been investigated by performing electronic structure calculations of the doublet potential energy surfaces and RRKM estimates of the product branching fractions. According to our results, the insertion of N(2D) into one of the sigma CH bonds of acetonitrile leading to the formation of cyanomethanimine (also known as iminoacetonitrile) and the N(2D) addition to the CC triple bond of cyanoacetylene leading to the formation of dicyanocarbene are the main reaction pathways under the conditions typical of the upper atmosphere of Titan, the massive moon of Saturn. Other molecular products originating from other reaction pathways only give a minor contribution.Implications for the atmospheric chemistry of Titan, as well as implications in prebiotic chemistry and in the chemistry of the interstellar medium, are also noted.