Shares of Target, which has more than 1,760 U.S. stores and is getting ready to open stores in Canada, jumped 5.8 percent to $52.25 in premarket trading.
Target has been adding groceries to more of its stores, a move that boosts sales but also pressures profitability, as food carries lower margins than merchandise such as apparel.
Still, the second-quarter gross margin decline was not too steep. Gross margin declined to 31.6 percent from 32 percent.
The big win was the gross margin coming in better than expected, said Rob Plaza, senior equity analyst at Key Private Bank, who had anticipated gross margin would fall to around 31.2 percent to 31.3 percent.
A large part of Target's profit coming in ahead of expectations also came from the credit card business, he said.
Target said in January that it wants to sell its credit card receivables, or the debts that cardholders owe the retailer.
But it wants to keep control of the credit card operations, which are part of a key marketing strategy in which it offers a 5 percent discount to cardholders who pay with their Target branded cards.
Average receivables declined 12.4 percent to $6.2 billion, bad debt expense plunged to $15 million from $138 million and profit rose to $171 million from $149 million.
Target earned $704 million, or $1.03 per share, in the second quarter, up from $679 million, or 92 cents per share, a year earlier.
Analysts, on average, expected it to earn 97 cents per share, according to Thomson Reuters I/B/E/S.
Target was not the only retailer reporting better-than-expected results. Wal-Mart Stores Inc
Target forecast third-quarter earnings per share of 70 cents to 75 cents, and full-year earnings per share of $4.15 to $4.30.
Analysts were looking for Target to earn 71 cents per share this quarter and $4.12 per share this year.
Earlier this month, Target said second-quarter sales rose 5.1 percent to $15.9 billion, with sales at stores open at least a year up 3.9 percent.
(Reporting by Jessica Wohl. Editing by Robert MacMillan, Dave Zimmerman)