NEW YORK — American Airlines reached an agreement Friday with its pilots’ union to avoid having to cancel thousands of flights during the Christmas holiday season because of a glitch with the pilots’ schedules.

The two sides had disagreed on how to overcome the glitch, which had left thousands of flights scheduled without a captain, a co-pilot or both between Dec. 17 and Dec. 31 at dozens of airports including hubs in Dallas, Chicago and Miami.

American said that the two sides “have put that worry to rest to make sure our flights will operate as scheduled.”

American, the world’s biggest airline, has about 15,000 active pilots and expects to operate more than 200,000 flights in December.

The airline discovered the problem last week in its scheduling system, in which pilots bid each month for flying assignments based on seniority. The glitch let pilots drop scheduled flights — to take a vacation over Christmas, for example — even when there were no other pilots available for that flight. Normally such a request would be denied, especially during busy travel periods.

The airline had said it would avoid canceling flights by paying overtime and using reserve or on-call pilots. But the Allied Pilots Association lodged a protest against the plan, saying American was violating its labor contract by imposing a solution without union input, and was improperly restricting premium pay.

The union said it dropped its grievance after a day of talks that addressed the needs of both the pilots and the airline.

“With this agreement in principle, we anticipate that American Airlines will be able to maintain a full December schedule as planned for its passengers,” the union said.

Union spokesman Dennis Tajer said details will be released after pilots see the deal.

“Both sides got together to figure this out and now we are going to be flying jets over the Christmas holidays,” Tajer said.

The trouble for American Airlines comes two months after Irish low-cost carrier Ryanair said it would cancel more 20,000 flights between November and March after admitting it “messed up” the transition to a new system for scheduling employee vacations.

Shares of American Airlines Group Inc., which is based in Fort Worth, Texas, fell $1.49, or 3 percent, Friday to close at $49.