A simple, inexpensive, and versatile route for the synthesis of metal nitrides and carbides (such as Mo2N, Mo2C, W2N and WC) nanoparticles was set up. For the first time, metal carbides were obtained using urea as carbon-source. MoCl5 and WCl4 are in a first step contacted with alcohols and an appropriate amount of urea to form a polymer-like, glassy phase, which acts as the starting product for further conversions. Just by heating this phase it was possible to prepare either molybdenum and tungsten nitrides or carbides simply by changing the metal precursor/urea molar ratio. In this procedure, urea plays a double role as a nitrogen/carbon source and stabilizing agent (necessary for the nanoparticle dispersion). Molybdenum and tungsten nitride and carbides synthesized are almost pure and highly crystalline. Sizes estimated by WAXS range around 20 and 4 nm in diameter for Mo and W nitrides or carbides, respectively. The specific surface area was found between 10 and 80 m2/g, depending on the metal and the initial ratio of metal precursor to urea.