Walgreen Co posted higher-than-expected earnings by keeping costs in check and better managing its discounting, and its shares rose as much as 9 percent to their highest level since last year.

The largest U.S. drugstore chain also has been gaining prescription market share from rivals like Rite Aid Corp .

Walgreen said it filled 202 million prescriptions in the quarter, up 4.6 percent from the year ago and more than double the rate of gain by the rest of the industry.

Walgreen on Wednesday said that it also boosted sales while improving its gross profit margin 80 basis points to 28.5 percent.

They have been working for quite a while on managing expenses better, and that was one of the things they did a very good job of, said Meredith Adler, an analyst with Barclays Capital who has an equal weight rating on the company. I don't think it was any one thing, but there's a discipline about pretty much everything they do that was not there before.

The company, which competes with CVS Caremark Corp , Rite Aid Corp , Wal-Mart Stores Inc and others, has been able to cut back on profit-sapping promotions as it has improved its merchandise assortment and kept inventory under control.

Rite Aid last week posted a loss for its third quarter ended November 27 and said it filled 1.7 percent fewer prescriptions.

Walgreen shares are up more than 5 percent this year and CVS is up 8.5 percent, while Rite Aid shares are down 40 percent this year.

Walgreen also has been slowing down the pace of new store openings and converting thousands of stores to a new, streamlined format that reduces some of its pharmacists' administrative workload so they can spend more time talking with customers.

Net earnings for the first quarter ended November 30 rose to $580 million, or 62 cents per share, from $489 million or 49 cents per share for the same quarter in 2009.

Earnings included 2 cents a share inventory write-off for flu shots. Analysts on average forecast earnings of 54 cents a share, according to Thomson Reuters I/B/E/S.

Quarterly revenue rose 6 percent to $17.34 billion.

Same-store sales, or sales at stores open at least a year, were up 0.8 percent for the quarter. Front-end comparable store sales increased 0.4 percent.

Prescription sales, which account for nearly two-thirds of sales, were up 5.3 percent for the quarter. The increase in sales was driven by Walgreen's growing share of the retail prescription market, which ended the quarter at 19.7 percent.

The rise in prescriptions at Walgreen's stores does not represent a broader improvement in the industry, Adler said.

The company's pharmacies and clinics also administered 5.6 million flu shots, slightly more than last year's first quarter.

Executives said they could not predict how the current quarter would turn out. A large part of their holiday sales comes from last-minute shoppers this week, including on Christmas Eve and Christmas Day.

Walgreen shares closed up $2.02 or 5.5 percent at $38.85 on the New York Stock Exchange, off an earlier high at $40.20. CVS shares were up 1.4 percent at $34.95, while Rite Aid was down 2.2 percent at 90 cents.

(Reporting by Jon Lentz, editing by Dave Zimmerman, Matthew Lewis and Carol Bishopric)