WASHINGTON — The Food and Drug Administration on Tuesday gave the food industry three years to eliminate artery-clogging artificial trans fats from the food supply, a long-awaited step that capped years of effort by consumer groups and is expected to save thousands of lives a year.

Trans fats — a major contributor to heart disease in the United States — have already been substantially reduced in foods, but they still lurk in many popular products, including frostings, microwave popcorn, packaged pies, frozen pizzas, margarines and coffee creamers.

The agency announced its plans to act in 2013 and has since addressed more than 6,000 public comments. The decision Tuesday was final and would effectively remove industrial trans fats from the American diet by 2018, a change that the agency has estimated could prevent 20,000 heart attacks and 7,000 deaths from heart disease each year.

The food industry said it was pleased that the agency had given it three years to carry out the rule, but also said it planned to seek permission to keep using small amounts of trans fats in certain products, an indication of just how difficult it is to root them out.