As Walker's power and the size of his army grew, conservative politicians throughout Central America became increasingly anxious. Encouraged by Britain, the conservative governments of the other four Central America governments agreed to send troops to Nicaragua. In March 1856, Costa Rica declared war on the adventurer, but an epidemic of cholera decimated the Costa Rican forces and forced their withdrawal. Encouraged by this victory, Walker began plans to have himself elected president and to encourage colonization of Nicaragua by North Americans. This scheme was too much even for his puppet president Rivas, who broke with Walker and his followers and sent messages to Guatemala and El Salvador requesting their help in expelling the filibusters.
Undeterred, Walker proceeded to hold a farcical election and install himself as president. Making English the country's official language and legalizing slavery, Walker also allied himself with Vanderbilt's rivals in the contest for control of the transit route, hoping that this alliance would provide both funds and transportation for future recruits. His call for Nicaragua's annexation by the United States as a slave state garnered some support from United States proslavery forces.
In the meantime, forces opposing Walker were rapidly gaining the upper hand, leading him to attack his liberal allies, accusing them of half-hearted support. Most Nicaraguans were offended by Walker's proslavery, pro-United States stance; Vanderbilt was determined to destroy him, and the rest of Central America actively sought his demise. The British also encouraged opposition to Walker as a means of curbing United States influence in the region. Even the United States government, fearful that plans to annex Nicaragua as a new slave state would fan the fires of sectional conflict growing within the United States, became opposed to his ambitions.
The struggle to expel Walker and his army from Nicaragua proved to be long and costly. In the process, the colonial city of Granada was burned, and thousands of Central Americans lost their lives. The combined opposition of Vanderbilt, the British Navy, and the forces of all of Central America, however, eventually defeated the filibusters. A key factor in Walker's defeat was the Costa Rican seizure of the transit route; the seizure permitted Walker's opponents to take control of the steamers on Lago de Nicaragua and thereby cut off much of Walker's access to additional recruits and finances. Vanderbilt played a major role in this effort and also supplied funds that enabled the Costa Ricans to offer free return passage to the United States to any of the filibusters who would abandon the cause. Many took advantage of this opportunity, and Walker's forces began to dwindle.
The final battle of what Nicaraguans called the "National War" (1856-57) took place in the spring of 1857 in the town of Rivas, near the Costa Rican border. Walker beat off the attacks of the Central Americans, but the strength and morale of his forces were declining, and it would be only a matter of time until he would be overwhelmed. At this point, Commander Charles H. Davis of the United States Navy, whose ship had been sent to Nicaragua's Pacific coast to protect United States economic interests, arranged a truce. On May 1, 1857, Walker and his remaining followers, escorted by a force of United States marines, evacuated Rivas, marched down to the coast, and took the ships back to the United States...
Walker's activities provided Nicaraguans with a long- lasting suspicion of United States activities and designs upon their nation.
Originally a product of interparty strife, the National War ironically served as a catalyst for cooperation between the liberal and conservative parties. The capital was moved to Managua in an effort to dampen interparty strife, and on September 12, 1856, both parties had signed an agreement to join efforts against Walker. This pact marked the beginning of an era of peaceful coexistence between Nicaragua's political parties, although the onus of the liberals' initial support of Walker allowed the conservatives to rule Nicaragua for the next three decades. After Walker's departure, Patricio Rivas served as president for the third time. He remained in office until June 1857, when liberal General Máximo Jérez and conservative General Tomás Martínez assumed a bipartisan presidency. A Constituent Assembly convened in November of that year and named General Martínez as president (r. 1858-67).