David Skeel is a professor of bankruptcy law at the University of Pennsylvania Law School.

The $816 million art-for-pensions deal that is designed to preserve the Detroit Institute of Arts collection is fascinating, imaginative and clever. But it’s almost certainly illegal. And I’ll show you why.

Were it legal, the deal would help solve two very big problems. The first is Detroit’s radically underfunded pensions, which are at least $3.5 billion in the hole, by the reckoning of Detroit Emergency Manager Kevyn Orr . Simple economics says that Detroit needs to slash these obligations. But the pensions are not lavish, and thousands of retired Detroiters depend on the pensions for their daily bread.

On the other side of the tracks is the Detroit Institute of Arts. Unlike most cities, whose art museums belong to separate entities, Detroit has owned its art museum since 1919, when the city was prospering. This means that it could put Bruegel’s “The Wedding Dance” or Matisse’s “The Window” on the auction block to pay creditors. The art world has been scheming to keep the art in Detroit, but creditors have insisted that they are entitled to its value. Added to this are the class — and, unavoidably, racial — implications of lavishing so much attention on art as ordinary Detroiters struggle.

Out of nowhere came the art-for-pensions scheme. The deal calls for Detroit to “sell” its art to a newly created trust that is required to keep the art in the city, using roughly $370 million raised from the Ford, Kresge, Knight and other foundations, $350 million from the state of Michigan (if the Republican legislature agrees) and the institute’s own funds. Not only would the new entity keep the art in Detroit but also the entire $816 million would be used to pay Detroit’s pensioners. The art world and Detroit’s pensioners both win. It’s almost like the deus ex machina solution to a Greek play.

The only problem is the bankruptcy law. A city’s treatment of its creditors in bankruptcy must be “in the best interests of creditors” and cannot “discriminate unfairly.” Best interests means that creditors must get more in bankruptcy than they would outside of bankruptcy; and no unfair discrimination means that Detroit can’t give a much higher recovery to one group of general creditors than to another.

The art-for-pensions deal runs roughshod over both requirements. Because the art would be used to pay only one group of creditors — the pension recipients — the excluded creditors may be worse off in bankruptcy than if Detroit had never filed. And Detroit’s current debt adjustment plan would include this influx of cash in a package that gives pensioners at least 95 percent of what they are owed while giving bondholders less than 20 percent.

In addition to these legal issues, the scheme has put members of the judiciary in an increasingly unjudicial role. The bankruptcy judge has resisted creditors’ requests to investigate the art to determine its value so they could explore alternative arrangements. The chief mediator in the case, a federal judge, has met with representatives of the foundations, lobbying them for money for the deal. Both judges are highly respected, but some worry whether the rule of law is being respected.

If Michigan wishes to help Detroit’s pensioners, it can simply pay them $350 million (or any other amount) outside of the bankruptcy process. Rhode Island did just this after Central Falls filed for bankruptcy in 2011. Detroit also can consider other ways to tap the value of its art while keeping the collection in the city. It can even arrange to give its pensioners somewhat greater recovery than other creditors, as long as the payouts are not wildly disproportionate.

What it can’t do is funnel the proceeds of a valuable asset to a single group of general creditors while excluding everyone else. U.S. bankruptcy law is designed to prevent precisely this kind of abuse.