I've worked as a Performance Development Engineer on diesel engines. While the other answers contain parts of the story - here's the real reason that diesel engine exhaust contains more NOx than gasoline engines.
First we'll take a look at the combustion process, and then we'll take a look at emissions control strategies.
The Combustion Process in Diesel and Gasoline Engines
As mentioned in other answers, NOx is primarily produced during combustion by a combination of time and high temperature. Nathan Kaemingk's answer explains this particularly well.
Nathan Kaemingk's answer to Why does diesel exhaust contain more nitrogen dioxide than other combustion engines?
Gasoline engines also produce NOx during combustion through the same principles - time and high temperature. However, gasoline combustion is different. In a traditional gasoline engine (not one of the new direct injection engines) the gasoline is perfectly mixed with air at the stoichiometric ratio prior to entering the combustion chamber. This means that there's precisely the amount of fuel necessary in the cylinder to burn all of the oxygen. This is different from a diesel engine in two major ways.
1. The diesel engine burns lean and power output is controlled by the amount of fuel injected into the cylinder. The gas engine always runs at the stoichiometric ratio (except for Wide Open Throttle and Deceleration Fuel Cutoff, which are exceptions) and the power output is controlled by throttling, reducing the pressure of the intake air, and thus the amount of fuel and air in the combustion chamber. Since the diesel engine burns lean that means there is always excess oxygen in the exhaust.
2. Since the gasoline is "perfectly" premixed with air before entering the combustion chamber the flame front is much different as there are no rich/lean areas of combustion as there are in a diesel engine, leading to much more uniformity in the resulting byproducts.
Also note (while not as important for this discussion) that diesel engines typically run higher compression ratios, around 16-18:1, vs. gasoline engines, typically running 9-11:1. Diesel engines are also compression ignition, relying on the high temperature generated by compression to ignite the fuel, whereas the fuel in a gasoline engine is ignited by a spark.
Emissions Control Strategies
Since gasoline engine exhaust contains no excess oxygen, gasoline engines can use a 3-way catalytic converter, which can reduce the NOx emissions in the exhaust by 99%. These catalytic converters have been in use since the early 1980s. If excess oxygen is present this reaction is much less effective and therefore much more NOx passes through unconverted. Since diesel engines always have excess oxygen in their exhaust they are unable to use the same 3-way catalytic converters that gasoline engines use.
The primary emissions controls strategies of diesel engines in the past have generally evolved from:
No emissions control (early 1970s)
Combustion control (mid 1970s)- lowering peak combustion temperature by lowering compression and retarding timing
Exhaust gas recirculation (2002/2004) - further lowering peak combustion temperature by displacing oxygen and reducing the speed of the flame
Higher pressure fuel injection (2000s) - better atomization and control of the fuel plume allowed for tighter control of the combustion process
Diesel particulate filters (2007) - didn't do anything to reduce NOx, but required to reduce emissions of particulates
Urea SCR systems (2010) - a selective catalytic reduction system relying on urea/ammonia to convert NOx into N2
The Urea SCR systems use a fluid that needs to be refilled at regular servicing intervals. Some of these fluids go by the name AdBlue, BlueDEF or DEF Fluid.
NOx emissions were regulated by the US Federal government for heavy duty diesel on-highway engines as follows:
1974 - 16 g/hp-hr (grams per horsepower-hour)
1979 - 10 g/hp-hr
1988 - 6 g/hp-hr
1991 - 5 g/hp-hr
1998 - 4 g/hp-hr
2004 - 2.5 g/hp-hr
2007-2010 (phased in by 2010) - 0.2 g/hp-hr
While diesel engine exhaust has historically contained more NOx, advances in aftertreatment and regulations in recent years have greatly reduced the amount of NOx (and particulate matter) that come out of the tailpipe of the newer diesel engines.