The Sun gives out radiation, mostly visible light with some ultraviolet and infrared. Much of this short wavelength radiation passes through the atmosphere and is absorbed by the Earth's surface, which warms up. The warm surface then emits radiation back out, but as longer wavelength infrared radiation.
Some gases in the atmosphere absorb this infrared radiation. These are greenhouse gases, such as carbon dioxide, methane and water vapour. The energy absorbed makes the bonds in their molecules vibrate more, and the molecules then re-emit the radiation in all directions, including back towards the surface. Less heat escapes to space, so the Earth is warmer than it would otherwise be. This is the greenhouse effect, and without it the Earth would be too cold for most life.
Nitrogen and oxygen make up most of the air but do not absorb infrared radiation, so they are not greenhouse gases. Adding more greenhouse gases means more infrared radiation is absorbed and re-emitted, so the average temperature rises.