While a modern aircraft engine is extremely reliable, and especially more so turbine engines found on many airliners, an engine failure event, albeit rare, does occur. This can be due to a wide multitude of reasons.
By far, the most common type of engine failure isn't technically a failure. In-flight shutdowns occur when the flight crew receives warning messages concerning the state of the engines. For example, if the flight crew get a low oil pressure warning, they shutdown the engine as a precaution to prevent a seizure, in the event that there is indeed an oil leak. Most of the time, the passengers won't even notice that an In flight shutdown has taken place!
An engine can fail because of a mechanical fault in its manufacturing process. The alloy's used to make the parts can be damaged by an irregular cooling process, formation of air molecules and introduction of contaminants. Compressor or turbine blades may crack, and when under extremely high revolutions, these spinning pieces of metal posses amazing amounts of energy, which can shred the whole engine to bits.
A bird strike can also damage the fan and compressor sections of an engine, resulting in a reduction of thrust or complete failure. Another rare form of engine failure is a flame out due to total fuel exhaustion. Fuel exhaustion can come about in a variety of ways. A fuel leak may be undetected until too late, an error in the fueling of the aircraft, or simply not paying enough attention to your fuel state. Fuel contamination (usually by water) may also lead to an engine flameout.
The ingestion of extremely large amounts of water and hail can cause the engines to simply flameout. Volcanic ash is known to also buildup inside the engine when ingested and with the high temperatures from combustion mold itself into a thick clay, forcing the engine to seize or shutdown.
In some situations, flames can be seen shooting from the engines, accompanied by loud bangs. This is known as a compressor stall and it occurs when the airfoil of the compressor stalls due to irregular air flow and patterns. There is not enough pressure for the hot combustion gases to be forced to flow out and these may reverse direction, or buildup until discharged by a loud bang.
One of the rarest of engine failures is a loss of the engine due to separation from the aircraft. Incorrect or weakened fittings and assembly methods are a prime culprit for this type of engine failure. An engine's thrust reversers, a system designed to re-direct the exhaust gasses, may also deploy mid-flight with usually disastrous consensuses. Although some aircraft are designed and licensed to use thrust reverse in flight, most are not. Therefore, a sudden deployment of the reversers may cause the engine to simply tear away from the airframe, and even worse, tear away some of the airframe with it.
Though that was a brief and uncompleted list of all the things that can go wrong with an engine, the majority of engines out there can and have kept functioning for thousands upon thousands of flight hours without the faintest mummer. Modern day engines are a miracle of engineering, and the fine engineers who deigned and built them deserve all the credit they can get.