Nicaragua has experienced several military dictatorships, the longest being the hereditary dictatorship of the Somoza family, who ruled for 43 nonconsecutive years during the 20th century. The Somoza family came to power as part of a U.S.-engineered pact in 1927 that stipulated the formation of the ''Guardia Nacional'' to replace the marines who had long reigned in the country. Somoza García slowly eliminated officers in the national guard who might have stood in his way, and then deposed Sacasa and became president on January 1, 1937, in a rigged election.