Engine braking helps in slowing the vehicle due to pumping losses in diesel and due to pumping vacuum in gasoline engine. This mainly helps the drivers whilst driving in the hilly sections.
There are several things in car which we make use of every time we sit behind the wheel but are unaware of them. One such feature is Engine braking. If your drive is a manual transmission congratulations, your car is enabled with this feature.
It is the concept of using the engine to brake in order to reduce the burden of brakes from increase in its temperature, brake fade etc. Also, it saves some amount of fuel too! But one should note that this does not completely eliminate the need of brakes as this cannot be done to bring the vehicle to a complete halt (the engine would stall) and Engine braking at lower gears is not advisable. It is often misunderstood with clutch braking which is a totally different concept and causes wear the clutch plate. So how it is achieved? Well, let us see.
Engine braking is achieved in different ways for spark ignition (Petrol) and compression ignition (Diesel) engines. Let us see the S.I. engine first.
When the accelerator pedal is released, the throttle valve through which air is fed to the engine closes and hence, a vacuum is generated in the cylinder. This means that the piston tries to pull in air which is not available and hence it slows down. The braking mostly happens during the suction stroke. Coming to the efficiency point, cars rolling out these days cuts off the fuel supply when it senses the engine is running at a higher rpm to stall.

In diesel however, we do not have throttle valve and hence there are 2 ways achieving this. The first method is similar to the one seen above except that the throttle valve is placed in the exhaust manifold and the braking mainly happens during the exhaust stroke. The other way is to use a Jake brakes. Here, the exhaust valve is opened at the end of compression. Which means all the work given by the engine for compressing the air will be wasted as there will be no power stroke. This helps in slowing down the engine.

The main advantage of engine braking is,
1. It helps in improving the life of brakes. (from fade)
2. Saves fuel.
3. No wear as seen in clutch braking.
4. Becomes handy when going downhill. This is a very good safety feature as it maintains the brake temperature and it is not advisable to turn off the engine or shifting to neutral at such conditions.
In automatic transmissions, engine braking cannot be achieved but one can downshift to reduce the speed but this causes wear of the parts and rev matching can be handy in such situations.