A $2.5 billion pretax bill for safety recalls and a victims’ compensation fund slashed General Motors Co.’s second-quarter profit and highlighted the work it must do to close a profitability gap with rival Ford Motor Co., which reported stronger results for the quarter ahead of a critical product launch.

GM on Thursday reported a $278 million profit, off 80% from a year earlier, as special items offset North American operating-margin…