Martial law, an emergency status under which military authorities temporarily replace civilians, has been declared on at least 68 occasions in the U.S., according to the Brennan Center for Justice.
It has usually been imposed during periods of war, natural disaster or civil unrest. Andrew Jackson, then a general, used it first, during the War of 1812 in New Orleans. It was imposed in Hawaii, then a territory, during World War II. Its most recent use was in 1963, when Maryland's governor responded to race riots in the city of Cambridge.
The legal basis for martial law isn't well understood. The Constitution makes no mention of the power, Congress hasn't defined it and case law is sparse. Courts have not settled whether a president can make a declaration without congressional authorization.