LOS ANGELES — Chipotle Mexican Grill Inc. on Tuesday reported a sharp rise in sales at its restaurants as it recovers from food safety lapses that drove away customers but disclosing a data breach erased some of the stock’s after-hours rally.

Chipotle shares leaped 7 percent in extended trading after first-quarter profit also blew past Wall Street’s target.

But shares retreated when Chief Financial Officer Jack Hartung told analysts the chain was investigating “unauthorized activity” in its payment system from late March through mid-April.

Hartung said Chipotle had enhanced security and would notify affected customers. Shares were up 3.3 percent in after-hours trading at $487.11.

The Denver-based company reported a 17.8 percent jump in sales at restaurants open at least 13 months, better than the 15.5 percent gain expected by analysts polled by Consensus Metrix. Those sales plummeted 29.7 percent in the first quarter of 2016, when Chipotle was grappling with the effects of several high-profile food safety lapses.

Chipotle wooed back customers by giving away millions of dollars worth of free and discounted food, upgrading online ordering and adding spicy chorizo sausage to its menu.

It recently raised prices by as much as 5 percent in some markets, and is watching for any push back from customers, Hartung said.

The more than 2,300-unit chain in December removed co-Chief Executive Officer Monty Moran and returned founder Steve Ells as sole CEO, following pressure from activists including hedge fund manager Bill Ackman. Since then, the company also has announced sweeping changes to its board and its business.

Executives have begun to address operational weaknesses unmasked by the sales swoon. They have increased marketing and advertising spending, started using software for more efficient labor scheduling, and have begun reducing waste across its business, from the kitchen to dining rooms.

Net income for the first quarter of 2017 was $46.1 million, or $1.60 per diluted share, compared with a net loss of $26.4 million, 88 cents per diluted share, in the year earlier quarter. Analysts had expected a profit of $1.27 for the most recent quarter, according to Thomson Reuters I/B/E/S.

Shares in Chipotle flirted with $750 prior to the company being linked to 2015 outbreaks of E. coli, salmonella and norovirus that sickened hundreds of people in the United States.