Central America won its independence from Spain in 1821, and for a short time remained united as the five provinces of the Central American Federation. The belief that Europe would act militarily to return the former colonies to Spain forced the United States to issue the Monroe Doctrine in 1823, declaring the New World off limits to further European colonization and interference, paving the way for two centuries of political domination in Latin America.
The Central American Federation was short-lived, however: When Nicaragua withdrew from the federation in 1838, the remaining states opted to become individual republics as well and the federation dissolved.
Newly independent Nicaragua was anarchic for years, dominated by the independent, feuding city-states of León  and Granada  until 1845 when a national government was finally agreed upon (the political rivalries that endure to this day). In the early 19th century, export of cacao, indigo, and cattle allowed the landed and merchant classes to accumulate considerable wealth at the expense of the Native Americans and landless class. A nascent liberal class grew in León inspired by the French and American revolutions that sought for more equal distribution of wealth.
Nicaragua’s unique geography has inspired multiple plans for a transcontinental-canal, even today. During the California gold rush (1849–1856), prospectors transited Nicaragua courtesy of steamship baron and businessman Cornelius Vanderbilt’s Pacific Steamship Company, then operating in Panamá. Travelers bound for California sailed up the Río San Juan  and across Lake Nicaragua to the small port at San Jorge . There, they were taken by horse cart 18 kilometers across the narrow isthmus through Rivas  to the bay of San Juan del Sur .
Ships waiting in the harbor then carried the travelers north along the Pacific coastline to California. Vanderbilt dredged the channel of the Río San Juan and built roads, railroads, and docks on both coasts to accommodate the traffic. At about that time, the Leóneses, embroiled in a bitter battle with the Conservatives of Granada, enlisted the help of William Walker, an American filibuster who eventually installed himself as president of Nicaragua, razed the city of Granada , and caused a whole lot of trouble.
Though the relative peace of the 30-year Conservative period fostered many advances in infrastructure and technology, including the Granada—Corinto train and the telegraph, Nicaragua remained several decades behind its neighbors in coffee exportation and the economy mostly stagnated. The bourgeoisie became restless and rebelled, installing Liberal General José Santos Zelaya as president.
Zelaya was a fierce nationalist who, among other things, reclaimed the Atlantic region at gunpoint from its British occupants (the two administrative units of the Atlantic coast bore Zelaya’s name until the 1990s). Zelaya furthermore rejected Washington’s proposals to build a cross-isthmus canal through Nicaraguan territory while courting Great Britain to finance the construction of a transcontinental railway.
The United States, which since 1904 had been building the Panama canal, was unimpressed by the nationalist leader and his railway proposal and in 1909, sent the U.S. Marines to secure Zelaya’s ouster. The U.S. intervention reestablished the Conservatives in power until 1912, when Liberal and nationalist Benjamin Zeledón led another rebellion. This time the U.S. Marine occupation happened on a much larger scale: 2,700 marines landed at Corinto  and took immediate control of the railways, ports, and major cities.
Nicaragua became subject to the United States financially at about this time, as U.S. financial institutions began to quietly acquire coffee-export businesses and railway and steamship companies, easing Nicaragua into a credit noose. Under the watchful eye of the U.S. Marines, governmental control was handed over to the Conservatives, whom Washington thought would more faithfully represent U.S. business interests. But the Liberals staged 10 uprisings between 1913 and 1924, all of which the U.S. military quelled.
In 1924, Conservative President Bartolomé Martínez instituted a novel form of government—a power-sharing arrangement between the Liberals and the Conservatives at the local level. The United States withdrew Marines in 1925 but they were back within the year. No sooner had power sharing begun than ambitious Conservative Emilio Chamorro staged a coup d’état, seized power, and sparked the Constitutional War. The United States stepped in to prevent the imminent takeover by the Liberals, but because the Conservatives had discredited themselves, the United States was unable to simply hand the power back to them.
The deal they worked out was known as the Espino Negro Pact (named after the town where it was signed; Spanish for Black Thorn). It was a crucial moment for the Liberals. One of their generals, Augusto C. Sandino, was opposed to the pact, and fled with his men to the northern mountains to start a guerrilla war in opposition of the continued presence of the United States in Nicaragua. The leader of the Constitutional Army was forced to declare, “All my men surrender except one.”
The U.S. military tried unsuccessfully to flush Sandino from the mountains despite drastic measures like the aerial bombing of Ocotal , so in 1933, Washington tried a new approach. Withdrawing U.S. troops from Nicaragua, the United States formed a new military unit called the National Guard and placed young Anastasio Somoza García at its head.
During the presidency of Juan Bautista Sacasa, Sandino enjoyed overwhelming support in Nicaragua’s northern mountains as he was perceived to have successfully accomplished both the repatriation of both U.S. armed forces and the removal of Conservative oligarchy from power. But he represented a major threat to Somoza’s political and military ambitions.
In February of 1934, President Sacasa invited him to Managua  to negotiate an agreement. When Sandino left the presidential palace that night, several National Guard members ambushed and assassinated him on the streets of Managua. The National Guard immediately swept the northern countryside subsequently, destroying cooperatives, returning lands to their previous owners, and hunting down, exiling, imprisoning, or killing Sandino’s supporters.