Chemist here. The urea reacts with various nitrogen oxides (NO, NO2, hence NOx) reducing them to nitrogen (N2), and also yielding water and CO2 (tiny amount of CO2 compared to the regular exhaust). This takes out the harmful NOx, which is the source of that yellow smoggy look over cites at sunset.
Yes, the urea decomposes to cyanate ions, which further decomposes to ammonia and CO2. Lots more chemistry in that which excites the inorganic chemists, but as there are no hydrocarbons involved it’s not my area.