Rite Aid (RAD) revealed a surprise fiscal fourth-quarter profit on Thursday that beat Wall Street’s expectations as an inventory-accounting benefit masked slipping same-store sales.

Shares of the No. 3 drug-store company surged almost 10% on the earnings beat, which marked its second-straight quarterly profit following a tough stretch of more than five years of red ink.

Rite Aid said it earned $123.1 million, or 13 cents a share, last quarter, compared with a loss of $161.3 million, or 18 cents a share, a year earlier. Analysts had called for a loss of 2 cents a share. Net income was boosted by $175.4 million thanks to an accounting credit linked to inventories.

Revenue slid 9.7% to $6.46 billion, compared with the Street’s view of $6.43 billion. Rite Aid said sales were hurt by one less week this year and the impact of lower-cost generics on pharmacy sales. Same-store sales dropped 2% during the quarter.

“We generated outstanding results in the fourth quarter, which helped us to deliver one of the best full-year performances in company history," said CEO John Standley said in a statement.

Looking ahead, Rite Aid forecast fiscal 2014 EPS of 4 cents to 20 cents a share, which compares favorably with consensus calls from analysts for a profit of just 4 cents a share.

Management sees same-store sales ranging between down 0.75% and up 0.75%,  translating to net sales of $24.9 billion to $25.3 billion. The midpoint of that range, $25.1 billion, would narrowly trail the Street’s view of $25.17 billion.

Shares of Camp Hill, Pa.-based Rite Aid leaped 9.50% to $1.95 on the results and  upbeat guidance, putting them on track to extend their 2013 rally of 31.6%.

Follow Matt Egan on Twitter @MattMEgan5