Nitrogen-fixing bacteria turn nitrogen into ammonia, after which nitrifying bacteria convert it to nitrates. Plants can take up and use nitrates to help sustain their growth. Nitrification (the conversion of ammonia to nitrate) is an aerobic process, meaning it only takes place in the presence of oxygen. Denitrification, by contrast, takes place in the absence of oxygen, because denitrifying bacteria are using nitrate in place of oxygen as part of their metabolism.
The denitrifying bacteria first reduce nitrate to nitrite, then reduce it further to nitric oxide. Nitric oxide is further converted to nitrous oxide (N2O), which is finally turned into nitrogen gas. This process is catalyzed by a series of different enzymes. During the initial steps, the nitrate is used as an electron acceptor in place of oxygen (since oxygen's usual role in respiration is to act as the final electron acceptor). During the subsequent steps, the products of the initial reactions are turned into nitrogen gas.
If the microbes are stressed, they may not carry out the full denitrification process, and rather than releasing nitrogen gas, they may release some more undesirable intermediate form of the element. Nitrous oxide is the most prominent example. This substance is actually a more potent greenhouse gas than CO2; at high concentrations, it can help increase Earth's surface temperature. Moreover, as noted in a 2003 paper in the journal Applied and Environmental Microbiology, nitrous oxide concentrations in Earth's atmosphere have increased over the last century, presumably as a result of denitrification of excess fertilizer.
Denitrification reduces the level of available nitrogen in the soil, so from a farmer's point of view it's an undesirable but unavoidable process. Moreover, denitrification is ultimately part of a cycle where nitrogen is fixed, taken up by plants, freed by decomposers then returned to the atmosphere. These processes are collectively called the nitrogen cycle, and they're essential for plant growth and all other organisms that depend on plants -- including humans.