What do Israel’s assault on Gaza and the American War of 1812 have in common? Much more than meets the eye.

The stated purpose of the Israeli assassination of Hamas’s military leader, which provoked the conflict in Gaza, was to impede the group’s rocket firings on southern Israel. Yet the rocket fire has been going on for months.

Instead, the real reason for Israel’s sudden escalation of violence might just have been the Israeli election in two months. Although Israeli Prime Minister Benjamin Netanyahu was ahead in the polls, Barack Obama’s re-election in the United States gave the opposition hope, because Netanyahu was being criticized for spoiling relations with Israel’s primary benefactor by meddling in the U.S. election on the side of Mitt Romney. Perhaps Netanyahu decided to stanch the opposition’s momentum by starting a war. So far, the gambit seems to have worked: a recent Haaretz newspaper poll found that 84% of Israelis backed the war in Gaza, and 55% approved of Netanyahu’s performance, a substantial hike from his prior numbers.

In 1812, American President James Madison was faced with a similar situation. Americans have long read in their history books that the war was caused by the British impressing U.S. sailors into service in the Royal Navy and violations of American neutral trading rights. If one studies history closely, however, the real cause of the War of 1812 appears to have been the desire of the American congressional “war hawks” to grab British Canada.

The War of 1812 wasn’t the first time that Americans had invaded Canada; George Washington and many of his countrymen during the American Revolution were eager to invade and acquire that real estate. Also, the British had been interfering with neutral U.S. trade since Washington’s presidential administration in the late 1700s, as had the French, because the two European powers were battling in the Napoleonic Wars. Yet curiously, the region of the United States most harmed by this practice, and the British impressment of sailors, was New England, which dominated American maritime trade. Yet New England almost revolted against the U.S. government and refused to send troops to fight when the United States started a war with Britain, thus casting doubt on the idea that chronic interference with U.S. trade was the real cause of the war. Furthermore, war only occurred after the congressional war hawks were elected in 1810. And Madison needed their support to win in the presidential election year of 1812.

Social-science research in the United States indicates that American presidents are more likely to conduct military operations during election years. The problem for politicians, however, is that although wars can initially spike their popularity, that wave of good feeling can rapidly dissipate if the war goes bad. In American history, politicians actually have not fared well as a result of war.

In 1812, Madison foolishly started a risky and costly war for aggressive purposes that failed in all respects—including the conquest of Canada and achieving respect for U.S. neutral trading rights. The only development that saved Madison’s popularity from tanking upon this result was a surprise victory by Andrew Jackson over the British in the Battle of New Orleans after a peace treaty had already been signed, which gave the illusion of American victory.

If Netanyahu started this war with the Israeli election in mind, he is also undertaking a sizable risk. Netanyahu’s predecessor, Ehud Olmert, plummeted in the polls after his 2006 war with Hezbollah in Lebanon failed to keep that group from firing rockets into northern Israel and also incurred substantial Israeli casualties. Because Hamas is believed to have 10,000 rockets and, so far, has fired only about 1,000 of them, the group will probably be launching them long after this war is over. Groups such as Hezbollah and Hamas don’t have to beat the vastly superior Israeli military to win international prestige, all they have to do his hang in there. After being defeated militarily, they can still win politically and merely replace their stashes of rockets. Israel regularly wins wars militarily and loses them politically.

Instead of spending his time disproportionately killing Palestinians (the ratio is more than 100 Palestinians to few Israelis) at great risk to his political future, Netanyahu could better devote his time to reaching a comprehensive peace with them. He may not be as lucky in war as James Madison.