thumb|right|235px|Fort William and Mary in 1705 (inset)

Fort William and Mary was a colonial-era British fortress on the island of New Castle, at the mouth of the Piscataqua River in the Province of New Hampshire. Originally known as "The Castle," it was renamed Fort William and Mary circa 1692, after the accession of William III and Mary II to the British throne. During the American Revolutionary War (1775–1783) it was captured by rebel forces, recaptured, and later abandoned by the British. Following an 1808 rebuilding in response to increasing British hostilities, it was renamed Fort Constitution and served in the War of 1812. Another rebuilding and expansion was carried out in the wake of the Spanish-American War in 1899. The fort served actively through the first half of the 20th century and World War II.

In 1683, Governor Edward Cranfield fired longtime commander Captain Elias Stileman and replaced him with Walter Barefoote. In the aftermath of Gove's Rebellion, Edward Gove was held there awaiting transportation to Boston and eventually the Tower of London. He complained of the treatment he received from Barefoote.

Colonel Shadrach Walton commanded the fort during different periods at the end of the 17th and beginning of the 18th century.

In 1705, the fort was inspected by military architect Wolfgang William Romer who suggested several improvements that were not acted upon.

The fort also served to protect Kittery on the opposite shore of the harbor, now in the state of Maine, but then part of the Province of Massachusetts Bay. The Kittery side of the harbor was raided numerous times by the tribes of the Wabanaki Confederacy during the French and Indian Wars (1753–1763).

In 1770, John Cochran accepted the post of commander of the fort from Governor John Wentworth.

American Revolution

In 1774, it was the only permanently occupied military post in New Hampshire.

1774 raids

thumb|250px|right|Fort William and Mary sketch by [[Wolfgang William Romer (1705)]]

On December 14, 1774, local Patriots from the Portsmouth area, led by local political leader and rebel activist John Langdon, stormed the post (overcoming a six-man caretaker detachment) and seized the garrison's gunpowder supply, which was distributed to local militia through several New Hampshire towns for potential use in the looming struggle against Great Britain. On the following day, rebels led by colonial military officer John Sullivan again raided the fort, this time seizing with greater effort numerous heavy cannon, ammunition and supplies.

Fort Constitution

Following the Revolution, the fort was called "Castle Fort" or "Fort Castle". On July 4, 1809, an accidental explosion marred Independence Day / Fourth of July celebrations at the fort, killing a number of soldiers and civilians. The U.S. Secretary of War's December 1811 report on fortifications described Fort Constitution as "an enclosed irregular work of masonry, mounting 36 heavy guns... (with) brick barracks for two companies..." During the War of 1812 the fort was occupied and expanded with Walbach Tower, a Martello tower with a single 32-pounder cannon, being built in 1814, just before the conflict ended.

Over four decades later, during the American Civil War (1861–1865), Fort Constitution was projected to be rebuilt as a three-tiered granite fort under the new expanded, more formidable Third System of U.S. coastal defense fortifications. However, advances in weaponry, particularly the development and use of armored, steam-powered warships with heavy rifled guns, rendered the masonry walls design obsolete before they were finished. The fort's construction was abandoned in 1867 following the Civil War with the older now-obsolete Second System fort still largely intact and two walls from the revised expanded Third System cut short, built around parts of it.

Named for Union Army Brigadier General Elon J. Farnsworth (1837–1863), killed at the Battle of Gettysburg during the Civil War, the battery was completed in 1899, a year after the successful conclusion of the Spanish-American War.

It was joined in 1904 by the construction of adjacent Battery Hackleman, built primarily to defend a newly created underwater minefield against enemy minesweepers. Named for Union General Pleasant A. Hackleman, it had two 3-inch (76 mm) M1903 guns on pedestal mounts.

The pair of fortifications were similar to numerous other Endicott-style defenses built during the late 1890s and early 1900s on river mouths, harbors, and bays outside of major cities along the Eastern Seaboard and Gulf of Mexico.