For a depositor to be able to confidently entrust a bank with his money, it helps if there is some kind of guarantee that, no matter what may happen, he will be able to get his money back. Deposit insurance is the primary way to guarantee the security of a depositor's money. This is important because of the very real risk of bank failure. Dozens and even hundreds of banks fail, or become financially insolvent, every year. In the United States, depositors' money is insured by the Federal Deposit Insurance Corporation (FDIC).
The need for deposit insurance arises mainly from the fact that banks are in the business of lending money and collecting interest on it. This money comes from depositors' accounts, and in most cases, banks keep only a small percentage of their customers' money on reserve as cash at any given time. This practice, known as fractional reserve banking, is very common around the world and is considered to be completely ethical.
The danger lies in the fact that if a bank's customers sense that their bank is having some kind of financial problems, due to borrowers defaulting on loans or any unexpected hardship, their incentive is to get their money out while they still can. When a bank's depositors all do this at once, it is said that there is a run on the bank. Because a bank only holds a fraction of the total funds on reserve, not everyone will be able to get their money. Those who can get it, do so, and without any cash left on hand, the bank usually has no choice but to go out of business.
At least that's the way things went before deposit insurance. In the aftermath of the widespread bank failures of the 1930s, deposit insurance was instituted for banks in the United States during the Great Depression. Many other countries followed suit soon after. Deposits at credit unions also became insured as of 1970. As is the case in most countries, deposit insurance in the U.S. is government-run. Banks pay what amount to insurance premiums to the FDIC, who will step in if a bank fails and provide the bank's depositors a way to retrieve their money. In the event that this has to be done, it is usually a very orderly process, as distinct from a run on a bank.
Deposit insurance, as important as it is, is not unlimited. In most instances, there is a government-imposed cap on the amount of funds that any one depositor can be guaranteed to get back if the bank fails. This does not preclude someone from having accounts at multiple banks as a precaution, and in fact, most wealthy individuals do just that as part of a common strategy known as diversification.