Apple Inc. flexed its financial muscle with a record $100 billion plan to buy back stock from investors, as it reported strong gains in revenue and profit even as growth in the number of iPhones sold remained weak.

The results for Apple’s fiscal second quarter reflect a fundamental transformation reshaping the world’s most valuable company, turning a business centered on how many devices it ships into one built around high-end features and services for those devices.

Apple’s...