During the Civil War, the precious document was hidden behind wallpaper in a home in Virginia to keep Union soldiers from finding it.

Later, it sat in a closet in Kentucky, in a broken frame, stored in a cardboard box. And later still it was stuck behind a cabinet in the office of an energy executive outside Houston.

It was a rare parchment copy of the Declaration of Independence, made in Washington in the 1820s for founding father James Madison.

Now, the copy, one of 51 that scholars are aware of, has resurfaced via its purchase last month by billionaire philanthropist David Rubenstein.

It is one of the exquisite facsimiles made from the original handwritten calfskin document crafted in Philadelphia in the summer of 1776. Scholars say it bears the image of the Declaration that most people know, in part because the original is now so badly faded.

“This is the closest ... to the original Declaration, the way it looked when it was signed in August of 1776,” said Seth Kaller, a New York rare document appraiser who assisted in the sale. “Without these ... copies you wouldn’t even know what the original looked liked.”

Master engraver made copies

Two hundred of the facsimiles were ordered by Secretary of State John Quincy Adams, a future president, who was concerned about the already-worn condition of the 40-year-old original. Master engraver William Stone made the copies in his shop on Pennsylvania Avenue, and created an extra one for himself.

In 1824, the facsimiles were distributed to Congress, the White House, and various VIPs like Thomas Jefferson, John Adams and Madison. Each man got two copies.

In time, both of Madison’s copies vanished, and it is only now that one has surfaced, Kaller said. “There was no idea that it had survived,” he said.

The fate of the second Madison copy, and more than 100 others, is not publicly known.

When the Second Continental Congress approved the Declaration in Philadelphia on July 4, 1776, it sent a working manuscript, also now lost, to a local printer to set in type.

The printer produced several hundred copies for Congress and other officials the next day, Kaller wrote in a historical pamphlet.

On July 19, Congress ordered a handwritten, or “engrossed,” copy made on calf skin, to be signed by the members. The job went to Timothy Matlack, a congressional aide who was known for his superb penmanship.

This hallowed version now resides in the National Archives, so washed out that many signatures, including Thomas Jefferson’s, are either gone or barely visible.

It is largely through the foresight of John Quincy Adams that excellent copies of the original — exact except for a few interesting tweaks — ­survive today.

Kaller wrote that by 1820, the original had been handled, rolled, unrolled and marred by the efforts of earlier engravers to make decorative copies. “Every one of the worst things that could have happened to the original” had happened, he said.

John Quincy Adams gave it to Stone, and the engraver worked on copying it for about two years. Kaller said he believes Stone likely first traced the original with tracing paper. He then used the tracing to hand-engrave an image on a copper plate, from which the facsimiles were made.

But Stone may have made some minute textual changes, possibly to distinguish his copies from the original, Kaller wrote. The ornate “T” in the “The” of the “The unanimous Declaration ...” seems to have been slightly altered. In the Stone copies, a decorative diagonal line runs through the “T.” The line does not appear to be in the original.

In the original, there seems to be a heart-shaped flourish where the T is crossed that’s omitted in the Stone copy.

And Stone added a tiny imprint across the top of the page,”ENGRAVEDed by W.I. STONE, for the Dept. of State, by order of J.Q. ADAMS, Sect. of State, July 4th. 1823.”

Kept in a cracked frame

Before the newly resurfaced copy was found, it had been kept in a cracked frame, wrapped up inside a cardboard box in Michael O’Mara’s office outside Houston.

It had been there for 10 years and before that in his parents’ house in Louisville, when he was growing up.

His family once had it framed and put on the mantelpiece. His parents knew it had been passed down through his family from Madison. But in the 1960s it was considered “worthless,” O’Mara said.

When the frame cracked the document was taken down and stored in a bedroom closet.

“So for ... 35 years, it sat in a box, wrapped up, in a broken frame, in my mother’s house,” he said in a recent interview. “There was just not a lot of sentiment or value put on it. ... My mother couldn’t have cared less about the family history.”

The Declaration had been handed down to O’Mara’s mother, Helen, who was the great-granddaughter of Col. Robert Lewis Madison Jr., a doctor who had served in the Confederate Army and treated Robert E. Lee in the last years of Lee’s life.

Research indicates that the physician had gotten the document from his father, Robert Lewis Madison Sr.

Thus, the copy of the nation’s founding Declaration had passed through turbulent years of the country’s evolution, including the war that almost destroyed the document’s “united States of America.”