Oxygen and nitrogen react to form nitric oxide. Following is from Wikipedia:
The uncatalyzed endothermic reaction of oxygen ($\ce{O2}$) and nitrogen ($\ce{N2}$), which is effected at high temperature ($\pu{>2000 °C}$) by lightning has not been developed into a practical commercial synthesis (see Birkeland–Eyde process):
$$\ce{N2 + O2 -> 2 NO}$$
Why nitrous oxide is not formed can be explained through thermodynamics. For any chemical reaction to take place spontaneously, we look at a factor known as free energy available for that reaction. Gibbs's Free Energy is given by the equation:
$$\mathrm{\Delta G = \Delta H − T\Delta S}$$
The quantity $\ce{\Delta G}$ must be negative for a reaction to take
place spontaneously. Now, most of the nitrogen oxides are unstable with respect to molecular nitrogen and molecular oxygen and have a positive value for the Gibbs free energy change of formation. For the reaction $\ce{2N2 + O2 −>2N2O}$, we put the values in the equation and calculate the Gibbs Free energy to confirm that this reaction can't take place.
Now coming to our actual reaction, the entropy change is small and positive.
$$
\begin{align}
\ce{N2 + O2 -> 2NO} & \tag{ΔG_0 = 86.7 kJ/mol}\\
\end{align}
$$
The Gibbs free energy change can also relate to the equilibrium constant, K.
$$\mathrm{G = -RT ln K = -5.7 log K~~(in~kJ~at~298 K)}$$
At equilibrium, that is under thermodynamic control, the concentration of $\ce{NO}$ in the atmosphere should be $\pu{10^-15.5 atm}$ but actual concentrations of $\ce{NO}$ are significantly higher than this (approximately $\pu{10^-10 atm}$).
So, even though thermodynamics says that $\ce{NO}$ is unstable with respect to $\ce{N2}$ and $\ce{O2}$, it doesn't spontaneously break down to those elements. There is a high activation barrier that must be overcome between reactants and products. Nitric oxide is kinetically stable but thermodynamically unstable.
For more information, please read the article.
But the reaction doesn't stop here. It proceeds to form more more nitrogen oxides $\ce{NO_x}$. You can continue reading the article for more details.