"It's much stronger ad growth than we were expecting," said Ken Sena, an analyst at Evercore ISI.
Its mobile strength helped offset concerns about Facebook's big bets on other services like Whatsapp and virtual reality, divisions that are yet to turn a profit.
Slower growth in operating expenses also pleased shareholders.
The company's shares were $11.45 higher at $105.90 at the end of extended-hours trading.