Online retailer Amazon.com Inc. (AMZN) Tuesday posted a drop in quarterly profit but topped Wall Street expectations despite the costs of free and discount shipping programs.

Shares rose 9 percent in after-hours trade as the company also forecast third-quarter sales above some analysts' targets.

Second-quarter net income fell to $52 million, or 12 cents per share, from $76 million, or 18 cents per share a year earlier, and sales rose to $1.75 billion from $1.39 billion a year earlier.

Analysts on average had expected net income 73 billion, according to ReutersEstimates.

Excluding some items, Amazon profit was 16 cents per share, compared with the consensus target of 12.5 cents, Reuters Estimates said.

Paul Keung, an analyst at CIBC World Markets Corp., called profit margins "unimpressive" but in line with predictions and said he saw a "very strong free cash flow" in the quarter as well as strength in international and merchant services.

Looking ahead, the company forecast third-quarter net sales between $1.76 billion and $1.91 billion and operating income between $60 million and $90 million.

Analysts on average have predicted third-quarter sales of $1.8 billion.

Shares rose $3.38 to $41.12 in after-hours trade on Inet (search).