Hostess Brands and a key union agreed Monday to try to mediate their dispute -- an unexpected development that could spare the company from permanently shutting down.

The Bakery Workers union, which represents 5,000 of the 18,500 employees at the maker of Twinkies and Wonder Bread, went on strike on Nov. 9. The company had imposed paycuts and other concessions opposed by the union's membership.

On Friday, management announced a shutdown of Hostess and appeared before U.S. Bankruptcy Judge Robert Drain on Monday afternoon seeking approval to liquidate.

But Drain said he wanted the parties to try one last time to reach agreement. Drain will serve as the mediator at a session scheduled for Tuesday afternoon. Only one day of talks is set for now.

Hostess CEO Greg Rayburn said the company needs a final decision on Tuesday. Monday's hearing on the liquidation motion was rescheduled for Wednesday at 11 a.m.

Tom Becker, spokesman for Hostess, said operations at its plants and distribution centers nationwide remain shutdown at this time. They were closed Friday morning when the company announced plans to liquidate.

Related: Hostess announces it is closing

Rayburn had said on Friday that it was too late to save the company, even if the Bakers returned to work at that time. That belief was echoed by company attorneys in bankruptcy court Monday.

"It would be very hard for us to recover from this damage, even if there were an agreement," said Heather Lennox, one of the lawyers for Hostess.

But Drain was clear that he wanted every effort made to avoid liquidation before he would sign of off the the company's motion. He cited the 18,000 jobs at stake.

"I believe that mediation only works if the parties are willing to do it, but I'm also strongly suggesting that they should be willing to do it," he said.

Bakery Workers' union lawyer Jeff Freund wouldn't speculate about the chance for a deal following the hearing. He had told the court that the union had already spelled out what needed to be done in order to produce a viable company.

"The court very respectfully asked that we participate in mediation and we'll honor the court's request," Freund said.

Rayburn refused to handicap the chances for a deal.

"I guess there's always a chance," he told reporters. "We'll take all the help we can get. [But] it doesn't change our financial situation."

But he insisted that management would be pleased if it could avoid liquidation.

"Everybody would agree that 18,500 people out of work would be about as bad a result as you can get," he said.

Exclusive: Hostess bidder wants to keep employees, bakeries

Hostess has announced its intention to sell its brands and recipes for various products and other assets as a way to generate cash for its creditors. Even if the products are purchased by other companies and once again sold to consumers, most potential buyers are unlikely to rehire Hostess employees to produce or deliver those products.

One hope for the unions and the employees was raised earlier in the day Monday when private equity firm Sun Capital Partners disclosed it wants to buy Hostess as a going concern, including reopening the shuttered factories and continuing union representation of Hostess workers.

Before Sun Capital's interest was first reported by Fortune Monday, the unions' statements and filings seemed resigned to the fact that Hostess will be closed down and the hourly workers will be out of work.

The Bakery Workers union issued a statement Saturday citing mismanagement over a number of years for the company's troubles.

Related: Hostess jobs: 'Great' to 'Not worth saving'

"Hostess failed because its six management teams over the last eight years were unable to make it a profitable, successful business enterprise," said the union.

But it said its members understood when they went on strike that a shutdown of the company would likely occur.

"They were well aware of the potential consequences of their actions but stood strong for dignity, justice and respect," the union's said.

A spokesman for the Teamsters union, which represents 6,700 workers at Hostess, said he could not comment on the mediation.