Apple said it sold a record 5.5 million Macs in the September quarter, boosting sales by 21% year-over-year during a stretch when the overall personal computer business remained in the red.

The Cupertino, Calif., company sold 6.2% more Macs in the quarter than the previous record of 5.2 million set three years ago.

The Mac's $6.6 billion in revenue was its most ever, and its 16% of the company's total revenue of $42.1 billion was the highest since the September quarter of 2011.

Apple For the second straight quarter, the ASP, or average selling price, of Apple's Mac line dropped and sales climbed.

Apple credited strong back-to-school sales for the numbers. "The back-to-school season voted, and the Mac won and carried the day," CEO Tim Cook said during Monday's earnings call with Wall Street analysts.

Apple's Mac sales caught analysts short, beating the forecasts of every Wall Street analyst polled by Fortune. The company bested the 4.8 million average of nearly three-dozen analysts by 14%, an even larger disparity than for the previous quarter. None of the 32 financial experts surveyed by Fortune had pegged sales higher than what Apple recorded, although one -- Keith Bachman of BMO Capital -- came very close with his forecast of 5.51 million, just 10,000 shy of actual sales.

Even though the Mac's unit sales were only a fraction of the total personal computer shipments for the period -- according to IDC's estimates, the Mac accounted for just 7% of all personal computers -- its growth was again higher than the overall average, and by a huge margin. Earlier this month, IDC and Gartner had pegged the industry as down 1.7% and 0.5% year-over-year, respectively.

The quarter was the third consecutive that Apple set sales records, and was the fourth straight quarter that showed year-over-year gains. The latter was no coincidence since the comparative quarters were the four during which Mac sales contracted: Q4 2012 through Q3 2013. Still, Apple's one-year retrenchment was much shorter than the overall market's, which by IDC's estimate has had a 10-quarter run of declines.

The ASP, or average selling price, of the Mac line decreased 4% quarter-over-quarter, falling from $1,255 to $1,200.

The slip in ASP indicated a further tip toward lower-priced Macs. Apple has been aggressive in pricing its personal computers this year, with cuts to the MacBook Air line in April and the introduction of a less-expensive, less-powerful iMac in June. Apple also ran its usual back-to-school promotion this summer that handed gift cards to students and parents who purchased Macs.

If sales of the new $2,499 5K Retina iMac take off, the ASP could again climb. Most industry analysts believe the high-resolution iMac will sell in small quantities, however, so the likelihood of an ASP turn-around is improbable.

The Mac's increase in sales may have come, at least in part, from customers choosing a traditional personal computer, particularly the light, thin MacBook Air notebook, rather than an iPad.

Apple posted iPad sales of 12.3 million, down 12.5% year-over-year and off 7% from the June quarter, for the third consecutive quarter of unit declines.

In fact, the Mac beat the iPad in both revenue and percentage of revenue for the first time since the March quarter of 2011, a time when the iPad 2 had been on sale for only weeks.

Mac revenue was 25% higher than the iPad's during the September quarter. A year ago, the roles were reversed, when the iPad recorded 10% higher revenue than the Mac.

But Cook wasn't concerned: He was fine with cannibalization as long as Apple ate itself. "There are obvious cannibalization things that are occurring. I'm sure that some people looked at a Mac and an iPad and decided on a Mac," Cook said. "And I'm fine with that, by the way. I'm sure that some people will look at an iPad and an iPhone and decide just to get an iPhone, and I'm fine with that as well."

And iPad revenue should jump past the Mac in 2014's final quarter. The tablet is much more seasonally sensitive than the Mac and posts its biggest numbers during holiday quarters. Last year, for example, fourth-quarter sales of the iPad jumped 85% from the previous period, while Mac sales increased by just 6% sequentially.

Last week, Apple introduced new iPads, including the iPad Air 2 and iPad Mini 3, while also dropping the price of previous-generation models by $100. The lowest-priced iPad -- 2012's non-Retina iPad Mini -- now lists for $249, an all-time low for the line.