Luxury department store Barneys has hashed out a deal to be sold that could keep the Madison Avenue flagship alive — albeit on a smaller scale.

Saks Fifth Avenue is teaming up with licensing firm Authentic Brands Group to acquire Barneys out of bankruptcy for $270 million, sources told The Post. The deal, if approved by the court, could help save three Barneys stores — in Beverly Hills, Midtown Manhattan and Boston — and give Barneys a presence in thriving Saks stores, these sources said.

Under the deal, ABG would acquire the Barneys brand and Saks would pay a licensing fee to operate Barneys.com and create a Barneys store within Saks. The size of the Barneys mini-stores could be between 10,000 and 50,000 square feet, said a source with knowledge of the situation.

ABG is also in negotiations with Barneys’ landlord, Ashkenazy Acquisition, to keep open its stores in Beverly Hills and on Madison Avenue flagship, where its rent more than doubled this year — triggering its bankruptcy, this person said. The branding company, which owns Juicy Couture and Frederick’s of Hollywood brands, is also talking with Barneys’ Boston landlord Simon properties to keep that store open, this person added.

Any deal to save the Madison Avenue location would require Barneys to give up as many as six of its 10 floors, this person said.

ABG and Toronto-based Hudson’s Bay Group, which owns Saks, have emerged as the leading bidders for the high-end retailer, which filed for bankruptcy protection on Aug. 6 and has until Oct. 24 to find a buyer and avoid liquidation.

The Saks and ABG tie-up, which was first reported by The Wall Street Journal, will be presented for approval at a court hearing on Tuesday.

Despite plans to keep as many as three Barneys locations open for business, some Barneys staffers were crying Monday and fretting that they would lose their jobs as word of the deal leaked, an insider said. Some managers were encouraging staffers to “start looking for other jobs,” while several employees from the company’s Fifth Avenue headquarters snuck out midday to commiserate at a local watering hole, according to the source.

The Madison Avenue store, famous for its edgy window displays, has taken to decorating the store in large black-and-white signs making light of its embarrassing bankruptcy.

“Not closed,” blared one large sign. “Barneys till I’m dead,” declared another as a voice recording from a woman with a British accent reminded passersby that the department store is still open for business.

“Strut, strut, strut, we’re still here. We still got clothes,” the recording announced. “The internet was a mistake. The emperor still has clothes.”

If ABG is able to keep a handful of stores open — at a reduced rent — the stores could close for about a week after the holidays once their current inventory is liquidated, sources familiar with the situation told The Post.

“The Madison Avenue would close and possibly reopen,” depending on the lease negotiations, the source said. Closing the stores — and then reopening them — could give the brand a fresh start, the source added.

A week ago the leading bidder was fashion trade-show executive, Sam Ben-Avraham, who has been trying to line up $220 million in financing. There have also been reports that Gary Wassner, head of factoring company Hilldun Corp. is interested in talks with Barneys lenders Brigade Capital Management and B. Riley Financial to buy the storied retailer with which he has had a long professional relationship.

The ABG and Saks deal appears to be the closest to getting done, the source with knowledge of the talks told The Post.

Alexandra Steigard contributed to this story