Lawyers learn the law in order to work the legal system for the benefit of their clients. A good lawyer can act as an advisor, advocate, defender, and litigator for his client. For example, if you own a business, it is important to have legal counsel in order to understand what liabilities your business might run into and whether or not you are operating legally as regards licensure, labor/employment law, taxes, etc. An attorneys, or specialist attorneys can help you do that.
Lawyers are most often called upon when it is too late and something needs to be fixed. A person is being sued or has suffered damages due to the negligence or malfeasance of another. The attorney uses his knowledge of applicable law and procedure to win a favorable outcome from a court of law. There are general practice attorneys and attorneys who specialize in torts, corporate law, tax law, criminal law, family law, etc.
Most concisely stated, a lawyer is usually someone you never want to meet until you need him, but probably should in order not to need him!