TRENTON, N.J. — A federal court invalidated the key patent for one of Pfizer’s most lucrative medicines, potentially opening the door for cheaper generic versions 18 months sooner than expected and cutting into the drugmaker’s profit.

Pfizer Inc., still trying to make up for the loss of about $7 billion in annual sales since generic competition challenged its cholesterol fighter Lipitor in December 2011, could lose a couple of billion more if the court decision on the Celebrex patent stands. The world’s second-biggest drugmaker said it disagrees with the ruling and will pursue all available remedies, including immediately appealing Wednesday’s ruling by Judge Arenda Allen of Virginia’s Eastern District Court in Norfolk.

Celebrex, Pfizer’s fourth-bestselling product, brought in $2.9 billion in worldwide sales last year. The anti-inflammatory pill is widely used for arthritis and acute pain. Celebrex has been on the market for more than a decade, so Pfizer’s gross profit margin on the drug may exceed 90 percent.

Advertisement

Trading of Pfizer shares on the New York Stock Exchange was briefly halted before the announcement. Shares closed at $31.98, down 44 cents, or 1.4 percent, but near Pfizer’s 52-week high. In after-hours trading, shares fell another 7 cents.

Get Talking Points in your inbox:

An afternoon recap of the day’s most important business news, delivered weekdays.

The case involves a reissue patent that prevented US sales of generic versions until Dec. 2, 2015. Last March, the US Patent & Trademark Office granted Pfizer the reissue patent, which corrected what Pfizer called technical deficiencies in the original patent covering the conditions treated by the drug’s active ingredient, celecoxib. Those include acute pain and menstrual pain, rheumatoid and osteo arthritis, and a painful spinal joint disorder called ankylosing spondylitis.

Five makers of generic drugs have been seeking Food and Drug Administration permission to sell generic Celebrex starting on May 30, when the drug’s original patent expires.

The suit had been scheduled for a trial beginning on March 19, but Judge Allen told the parties last week she would rule on motions they had filed in the case, instead of holding a trial.

Advertisement

‘‘Odds are in favor of generics launching early,’’ Bernstein Research analyst Dr. Timothy Anderson wrote to investors. He estimates Pfizer’s earnings per share would then be reduced by 4 percent this year and 8 percent in 2015.

In another development for the drugmaker Wednesday, Pfizer said its blockbuster vaccine against pneumonia and other infections met its goal of preventing illness in vulnerable elderly patients in a large study.

The company’s Prevnar 13 protects against 13 strains of pneumococcal disease, which can also cause children’s ear infections and life-threatening bloodstream infections.

The study, which included about 85,000 patients aged 65 or older, found that compared with study participants getting a placebo, those getting the vaccine had about 46 percent fewer cases of pneumonia.