Title insurance protects against problems in a property's chain of ownership that a records search did not catch: an old lien that was never released, a forged signature on a past deed, an undisclosed heir with a claim, or an error in the public records. Unlike most insurance, it is paid once at closing and covers the past rather than the future — it defends the ownership you thought you were buying.
There are two flavors. A lender's policy, which lenders require, protects only the lender's loan balance. An owner's policy protects your equity, and on a purchase it is usually the optional line item worth taking, since a title defect can otherwise cost you the property itself. Who customarily pays for which policy varies by state and is negotiable in the contract.