Shares soared more than 7 percent in premarket trading following the report.
The Purchase, New York-based credit card and global payments processor earned $348.9 million, or $2.67 per share, in the period ended June 30. That compares with a loss of $746.7 million, or $5.70 per share, in the same period a year earlier.
Results in the year-ago period were weighed down by a $1.65 billion charge related to a litigation settlement.
Revenue climbed nearly 3 percent to $1.28 billion.
Both profit and revenue came in ahead of analyst estimates. On average, analysts projected earnings of $2.42 per share on revenue of $1.25 billion, according to a poll by Thomson Reuters.
MasterCard said higher revenue was driven by pricing changes, an increase in the number of transactions processed and a decrease in rebates and incentives.
These factors were partially offset by lower gross dollar volumes. Gross dollar volume was down 0.6 percent to $595 billion on a local-currency basis compared with the second quarter of last year. Worldwide purchase volume fell 0.7 percent to $450 billion.
The number of transactions processed increased 7.9 percent to 5.6 billion, MasterCard said.
Excluding special items, total operating expenses declined 13 percent to $722 million as the company cut back on advertising and marketing and general and administrative expenses such as travel. Favorable foreign currency fluctuations also contributed to the decline in expenses.
MasterCard shares advanced $13.45 to $202 ahead of Thursday's market open. They have ranged from $113.05 to $272 over the past year.
MasterCard's results come one day after an upbeat report from rival Visa Inc., which said its fiscal third-quarter profit jumped nearly 73 percent as cost-cutting helped offset declining payment processing volume.