The advisory committee to the Food and Drug Administration voted 20 to 2 that the benefits from the weight loss provided by the drug, Qnexa, more than offset the potential risks of heart problems and birth defects.

The strongly positive vote, which was not widely expected, represents a stunning comeback for Qnexa and for its developer, the drug company Vivus.

In 2010, the same advisory committee, with a somewhat different membership, recommended 10 to 6 against approval, and the F.D.A. then rejected the drug.

Some committee members who opposed it last time said they were reassured this time that steps would be taken to minimize the risks, such as by making it hard for pregnant women to get the drug.

They also seemed persuaded by the view expressed by Vivus and by some obesity specialists who testified at the hearing that obesity itself causes health problems and that there is a pressing need for treatments.

“There is an urgent need for better pharmacologic options for individual patients,” said Elaine H. Morrato, an assistant professor at the University of Colorado, Denver, who voted no in 2010 and yes on Wednesday.

“I believe that Qnexa demonstrated a meaningful efficacy benefit and that there are consequences to nontreatment of obesity,” she said.

The F.D.A. is expected to decide whether to approve Qnexa by April 17. It usually follows the recommendations of its outside advisers, but not always.

In 2011, it rejected a different obesity drug that had been endorsed by the advisory committee.

Vivus shares, which did not trade during regular hours Wednesday, nearly doubled in after-hours trading to $21.05. Shares of Orexigen Therapeutics and Arena Pharmaceuticals, two other small companies trying again for approval again after their obesity drugs were rejected in the last two years, also rose after hours.

The F.D.A. has traditionally been cautious about diet pills because of previous safety issues, such as the heart valve damage caused by a component of the fen-phen combination. With a third of adult Americans obese and another third overweight, an obesity drug might be taken by millions of people, including many who just want to shed a few pounds.

The only prescription diet drug for long-term use is Roche’s Xenical, approved in 1999 but rarely prescribed because of limited effectiveness and embarrassing side effects.

That has led to pressure on the F.D.A. to take obesity more seriously. “Our members are telling us they are frustrated because there really aren’t enough tools in the toolbox,” Joseph Nadglowksi Jr., president of the Obesity Action Coalition, testified. The coalition represents obesity patients but also counts Vivus as a member.

The lopsidedness of the vote could not be predicted from the committee’s discussion during the daylong meeting in Silver Spring, Md., because many committee members seemed to be on the fence until the final tally.

Qnexa is a combination of two existing drugs — the stimulant phentermine, which was the surviving part of the fen-phen combination, and the epilepsy and migraine drug topiramate, also known by the brand name Topamax.

Use of Qnexa led to an average weight loss of around 10 percent of body weight after one year, though some weight was gained back in the second year. There also seemed to be positive effects on blood pressure and blood sugar, some blood lipids, and quality of life.

Dr. Michael S. Lauer, a cardiologist at the National Heart, Lung and Blood Institute, called the increased heart rate a danger signal and said the drug might increase the risk of heart attack even though it lowered blood pressure and blood sugar.

“The consequence of making a mistake here is huge,” said Dr. Lauer, who was one of the two committee members to vote against approval. “We’ve unfortunately had many examples of having made mistakes before,” he said, citing hormone therapy for post-menopausal women, which he said looked medically sensible but turned out to be harmful.

Vivus, which is based in Mountain View, Calif., has agreed to do a large clinical trial to assess whether Qnexa causes an increased risk of heart attacks and strokes. Most committee members seemed to believe that the study could be done after the drug was approved.

To lower risks, Vivus also said that it would recommend that the highest dose of Qnexa be used only rarely and that patients who did not lose at least 3 percent of their weight within three months stop taking the drug.

Much of the discussion was on studies showing that use of topiramate during pregnancy led to a twofold to fivefold greater risk of babies being born with cleft lips and, sometimes, cleft palates.

Vivus and the F.D.A. are discussing ways to make sure pregnant women do not take the drug.

A version of this article appears in print on February 23, 2012, on page B1 of the New York edition with the headline: In Reversal, F.D.A. Panel Endorses A Diet Pill. Order Reprints|Today's Paper|Subscribe