A rocket engine nozzle is a propelling nozzle (usually of the de Laval type) used in a rocket engine to expand and accelerate the combustion gases produced by burning propellants so that the exhaust gases exit the nozzle at hypersonic velocities.
Simply: the rocket (pumps and a combustion chamber) generates high pressure, a few hundred atmospheres (Bar). The nozzle turns the static high pressure high temperature gas into rapidly moving gas at near-ambient pressure.
The de Laval nozzle was originally developed in the 19th century by Gustaf de Laval for use in steam turbines. It was first used in an early rocket engine developed by Robert Goddard, one of the fathers of modern rocketry. It has since been used in almost all rocket engines, including Walter Theill's implementation, which made possible Germany's V-2 rocket.
The optimal size of a rocket engine nozzle to be used within the atmosphere is achieved when the exit pressure equals ambient (atmospheric) pressure, which decreases with altitude. For rockets travelling from the Earth to orbit, a simple nozzle design is only optimal at one altitude, losing efficiency and wasting fuel at other altitudes.
Just past the throat, the pressure of the gas is higher than ambient pressure and needs to be lowered between the throat and the nozzle exit by expansion. If the pressure of the jet leaving the nozzle exit is still above ambient pressure, then a nozzle is said to be "underexpanded"; if the jet is below ambient pressure, then it is "overexpanded".
Slight overexpansion causes a slight reduction in efficiency, but otherwise does little harm. However, if the exit pressure is less than approximately 40% that of ambient, then "flow separation" occurs. This can cause jet instabilities that can cause damage to the nozzle or simply cause control difficulties of the vehicle or the engine.
In some cases it is desirable for reliability and safety reasons to ignite a rocket engine on the ground that will be used all the way to orbit. For optimal liftoff performance, the pressure of the gases exiting nozzle should be at sea-level pressure; however, if a rocket engine is primarily designed for use at high altitudes and is only providing additional thrust to another "first-stage" engine during liftoff in a multi-stage design, then designers will usually opt for an overexpanded nozzle (at sea-level) design, making it more efficient at higher altitudes, where the ambient pressure is lower. This was the technique employed on the Space shuttle's main engines, which spent most of their powered trajectory in near-vacuum, while the shuttle's two solid rocket boosters provided the majority of the liftoff thrust.