History beckoned to Sandy and Duane Heiler as they planned their retirement. The empty-nesters decided to sell their 1960s Colonial in Potomac and went searching for an authentic Colonial like the 1660s home they had renovated in Sudbury, Mass., about a decade earlier.

At the recommendation of their son Chris, the Heilers checked out properties in Brookeville, a tiny Montgomery County town of 136 residents.

Then they hit the jackpot.

The couple discovered that the oldest and most historically significant dwelling in the village, the Madison House, was for sale. After purchasing the property in 2007, the Heilers spent two years restoring and renovating nearly every square inch with the utmost respect for its past.

Their skill and dedication in completing this top-to-bottom effort led them to another grand prize: becoming the winners of The Post’s Historic Home Contest.

“The Brookeville house was unique in the owners’ understanding of history and their charming fanaticism to authentically preserve it,” said Simon Jacobsen, a partner of D.C.-based Jacobsen Architecture and one of three contest judges. “The science of the research and craftsmanship is obvious but not contrived. Best of all, it is a fully functional house, and it is not treated as a doily museum.”

The Federal-style brick residence, built during the late 1700s, could have ended up as a museum, given its storied past. During the War of 1812, President James Madison stayed in the house after fleeing Washington during the British invasion of the capital and the burning of the White House. On Aug. 26, 1814, Madison arrived in Brookeville and spent the night in the “best” bedroom of the house before leaving the next afternoon.

Sandy Heiler, 72, a retired computer scientist, currently serves as chairman of the Brookeville War of 1812 Bicentennial Commission. She earned a master’s degree in preservation and architectural history when she was in her 60s, and she ensured that all the remodeling was based on research so it didn’t compromise the home’s original features.

“I love doing the detective work on the stuff that happened here,” she said. “This house is very special, particularly in its importance to presidential history.”

The Heilers approached the remodeling of the house with the goal of saving as many of the original features as possible, including windows and doors, heart pine floors, woodwork and built-in cabinets in three rooms. “The trick with an old house is to preserve it, make it livable and beautiful, and we tried to achieve all three,” Heiler says.

In spaces renovated by previous owners where fewer historic features survived, the Heilers made practical improvements such as upgrading the kitchen and bathrooms. “We tried to strike a balance between maintaining the integrity of the building and making it comfortable,” says Duane Heiler, 78, a retired investment adviser.

The Heilers estimate the entire renovation of the Madison House cost about $250,000, not including the value of their own work in repairing windows, floors, woodwork and plaster.

Each upgrade was undertaken to allow the architecture of the old house to remain primary. The sagging third floor was shored up by a steel ceiling beam, now cased so it looks like wood. Even the kitchen refrigerator is disguised to resemble a cabinet.

“The owners embody the reverence for history that is that basis of any truly successful preservation project,” said judge Katherine Malone-France, director of outreach and education in the National Trust for Historic Preservation’s historic sites department. (Malone-France, whose former employer helped improve the Heilers’ kitchen, was involved in the financial aspects of that project and recused herself from voting on this house).

In the entrance hall, a copy of Madison’s letter to his wife, Dolley, written in the house on the second day of his stay, hangs next to the front door. Displayed on a nearby table is a startling discovery made by Sandy Heiler while planting tulips in the front garden — part of a clay pipe decorated with the Great Seal of the United States. “It may have been dropped by Madison or one of his companions during his Brookeville visit,” she speculates.

Next to the foyer, the parlor captures a period look with a needlepoint fire screen and grandfather clock from the 1700s, and a harpsichord assembled by the couple. One of its windows once framed the front door where Madison probably entered the home.

“There is a real Quaker aesthetic throughout the house,” says Sandy, pointing to the white-washed walls and painted trim in the rooms.

That’s no coincidence since Richard Thomas, a Quaker, may have built the house for himself and his wife, Deborah Brooke. The pair founded Brookeville in 1794 on land inherited from her father. Two of the original surveying stones used to lay out the town still rest in the Heilers’ front yard.

At the time of Madison’s visit, the house was owned by Caleb Bentley, a clockmaker and silversmith who made cornerstone plaques for the White House and U.S. Capitol. His second wife, Henrietta, a friend of Dolley Madison, gave up her bedroom to the president during his stay.

Bentley worked in the house in a room next to the parlor. In 1802, he was appointed by Thomas Jefferson as Brookeville’s first postmaster and ran the post office and a store from his workshop.

The Heilers now use the former post office as a family room to watch television, which they hide in an early 1800s cabinet. Their careful attention to historic detail extends to the walnut floor, where they filled the gaps between the boards with hemp rope to create an authentic look.

“When you walk through the house, you get the feeling of another era,” said Post staff writer Jura Koncius, another contest judge. “The owners are passionate about history and made the house look warm and real without being cliched about it.”

The original mantelpiece was missing from the family room’s large fireplace, so Duane made a new design inspired by the 18th-century mantels in the historic Hammond-Harwood House in Annapolis. On the opposite side of the room, the couple built a new partition four feet from the original wall to create space for a new powder room, laundry and closet.

In the 1840s, the original kitchen on the west side of the house was converted into a dining room, and a tiny new kitchen wing was added to the rear. Until then, the space now serving as the entrance hall was used for dining.

To create a larger kitchen, the couple completely overhauled the small cooking space and turned the remnants of a wood storage shed into a pantry. “The shed had fallen down by the time we bought the house,” says Sandy. “There was a ghost of the original that convinced the local preservation commission that an attached building had been there and we could restore it.”

The brick-enclosed pantry expands the adjacent kitchen with more storage, a soapstone utility sink and countertops made of recycled pine boards. The Heilers undertook the project with help from their neighbor, Brookeville architect Miche Booz, and Oak Grove Restoration Co. of Laytonsville.

Upstairs on the second floor, the homeowners turned one of the bedrooms into a library. The smallest bedroom had already been turned into a bathroom by a previous owner, so the Heilers updated it with a new vanity. They restored the original heart pine floor, which had been hidden under layers of vinyl tile and linoleum. The master bath, added in the 1960s, was remodeled with a new sink and closets.

The original bedroom where Madison stayed is now reserved for guests. Duane opened the fireplaces in this room and the library by removing layers of plaster and sheetrock.

Adding the final touches to the house became a family affair: Duane built the kitchen cabinets and several tables; son Chris, a cabinetmaker, made the tall desk and hutch in the kitchen; and the Heilers’ eldest daughter, Beth Simonson, decorated tile backsplashes, bathroom sinks and pieces of furniture. Sandy pitched in by painting canvas to create the patterned floor cloths in several rooms.

Next on the Heilers’ agenda is fixing up the dilapidated smokehouse in their side yard. Constructed of logs, the small structure may be older than the Madison House, according to Sandy.

“When you take that type of approach — guard every bit of historic fabric and let the features of the building tell its story — the result is a place where authenticity is palpable,” Malone-France says.

Deborah K. Dietsch is a freelance writer.