SAN FRANCISCO — With an eleventh-hour order, Gov. Jerry Brown averted a strike of San Francisco’s Bay Area Rapid Transit system late Sunday night, setting at ease the minds of many anxious commuters.

In the order, Brown named a board of investigators for a seven-day inquiry into the contract dispute that threatened to shut down, beginning Monday, one of the region’s major train lines.

Brown’s order comes under a law that allows the state’s intervention if a strike will significantly disrupt public transportation services and endanger public health.

“For the sake of the people of the Bay Area, I urge — in the strongest terms possible — the parties to meet quickly and as long as necessary to get this dispute resolved,” Brown said in the order.

Bay Area Rapid Transit managers and union leaders had returned to the bargaining table Sunday in hopes of heading off a strike that would have created traffic nightmares for San Francisco area commuters for the second time in a month.

Representatives from BART management and the agency’s two largest employee unions negotiated for about 14 hours Saturday and resumed bargaining Sunday morning as a midnight deadline loomed. Brown’s order came at around 10:30 p.m. Sunday.

Big differences remain on key issues including wages, pensions, worker safety and health care costs, but the parties expressed some optimism that an agreement could be reached to avert a strike planned for Monday.

“The parties made some important but incremental moves yesterday, and I hope to get to a deal,” Josie Mooney, chief negotiator for the Service Employees International Union 1021, said Sunday before heading into negotiations. “If the parties work very hard, then it’s certainly possible in the amount of time we have left.”

“There was definitely movement from both sides,” BART chief negotiator Thomas Hock said as he left negotiations late Saturday night. “Hopefully, if we keep moving, we will get to a proposal that both sides can agree to.”

BART’s two largest unions issued a 72-hour notice Thursday that employees would walk off the job if they didn’t reach agreement on a new contract by midnight Sunday.

“BART really is the backbone of the transit network. No other transit agency has the ability to absorb BART’s capacity if there’s a disruption,” said John Goodwin, spokesman for the Metropolitan Transportation Commission.

In the event of a strike, transit agencies had planned to add bus and ferry service, keep carpool lanes open all day and even give away coffee gift cards to encourage drivers to pick up riders. They were also encouraging workers to avoid peak traffic hours or telecommute if possible.

When BART workers shut down train service for four days in early July, roadways were packed and commuters waited in long lines for buses and ferries. The unions agreed to call off that strike and extend their contracts until Sunday while negotiations continued.

Bay Area and state officials have been pressuring BART managers and union leaders to reach an agreement this weekend, saying a strike would create financial hardship for working families and hurt the region’s economy.