United Parcel Service (UPS -1.51%) today reported blowout second-quarter earnings fueled by strong e-commerce and healthcare demand. The surge was expected, but the company's ability to generate solid margins on that business caught Wall Street by surprise.

UPS reported adjusted second-quarter earnings of $2.13 per share on revenue of $20.5 billion, easily outpacing the $1.07 per share on $17.5 billion in sales consensus estimate. The shipping company saw volumes surge 20.9%, with domestic shipments up 22.8% and business-to-consumer deliveries up 65% in the U.S.

A UPS driver in front of his truck.

Image source: United Parcel Service.

Investors knew going in to expect volume increases as consumers were stuck at home and shopping online, but business-to-consumer shipping tends to be the least profitable portion of UPS' business. Domestic margins came in at 9.3%, down from 11% in the second quarter of 2019, but better than analysts had expected. Overall operating margin fell just 60 basis points to 11.4%, fueling the earnings-per-share beat.

"Our results were better than we expected, driven in part by the changes in demand that emerged from the pandemic, including a surge in residential volume, COVID-19 related healthcare shipments, and strong outbound demand from Asia," CEO Carol Tome said in a statement.

With the pandemic continuing to alter consumer behavior, the second quarter's success should flow into the current period as well. Shares of UPS were up 15% around 1:30 p.m. Thursday following the release of the results.

Risks remain. UPS did not provide any guidance due to uncertainty about the timing and pace of the economic recovery. And if the shift toward e-commerce proves to be permanent, UPS could face a period of investment in the years to come to handle higher volumes, or risk the system being overwhelmed during peak holiday shipping season.