Apple has fallen short of Wall Street’s earnings expectations for the first time since 2004.

The company reported earnings of $6.62 billion (or $7.05 per share) in its fiscal fourth quarter. While that represented a 54% gain in net income, it was notably less than the $7.39 analysts had expected. Shares fell roughly 6% in after-hours trading.

This was just the third time since 2002 that Apple has missed analyst expectations. The numbers did greatly exceed Apple’s own guidance, but investors and analysts tend to ignore those figures given how fiscally conservative the company is.

Lower-than-expected iPhone sales were to blame for the shortfall. Apple sold just over 17 million of its smartphones between July and September. The Street was looking for sales to be in the 18 million-20 million range. (Apple sold 20.3 million iPhones in its fiscal third quarter.) The iPad, however, topped sales estimates, moving 11.1 million units in the quarter, up 20% over the previous quarter and 166% year over year.

Apple shrugged off any disappointment by analysts.

“We are thrilled with the very strong finish of an outstanding fiscal 2011, growing annual revenue to $108 billion and growing earnings to $26 billion,” said CEO Tim Cook in a statement. “Customer response to iPhone 4S has been fantastic, we have strong momentum going into the holiday season, and we remain really enthusiastic about our product pipeline.”

While Tuesday’s announcement was disappointing on some levels, it was hardly a fiasco. The company’s gross margins increased from 36.9% to 40.3%, indicating greater profitability. Apple also offered a better-than-expected forecast for the first quarter due to the tremendous response to the iPhone 4S.

Apple reported Monday that opening weekend sales of the iPhone 4S set a new record at more than 4 million units — more than double the number of units sold when the iPhone 4 hit shelves.

An expanded number of carriers gets part of the credit. When the iPhone 4 hit, AT&T was the only mobile company to stock it. (Verizon became a carrier several months later.) This time, both carriers — as well as Sprint — had the phone on day one.