Costa RIca Capital San Jose

How San José Became the Capital of Costa Rica

Costa RIca Capital San Jose
(Photo by MARTIN BERNETTI / AFP)
How San José Became the Capital of Costa Rica (1823 Story)

San José wasn’t always the capital of Costa Rica. For 260 years it wasn’t even close — it was a scattered settlement of tobacco farmers sitting in the shadow of the much older, much grander city of Cartago. Then, on a hilltop between the two towns one April morning in 1823, the question of who would lead the new country was decided by gunfire. This is the story of how Costa Rica’s capital moved.

From colonial backwater to capital: when did San José become the capital of Costa Rica?

The short answer: San José became the capital of Costa Rica in 1823, following a brief civil war fought just months after independence from Spain. The longer answer involves a coup, a battle on a foggy ridge, a “rotating capital” law that almost broke the country, and a second civil war that finally settled the matter.

To understand why it happened, you have to start with the city that used to be the capital.

Cartago: the original capital of Costa Rica (1563–1823)

Founded in 1563 by the Spanish conquistador Juan Vázquez de Coronado, Cartago was Costa Rica’s first permanent Spanish settlement and its colonial capital for the entire Spanish era. It sits about 40 minutes southeast of modern San José, in the highlands near the Irazú Volcano — a region that offered fertile volcanic soil, defensible terrain, and a cool climate the Spanish found agreeable.

For nearly three centuries, Cartago was where the colonial governor lived, where decrees were issued, and where the small province’s political life happened. Costa Rica itself, though, was a backwater of the Spanish Empire — too remote from Guatemala City to matter much, too poor in gold to attract real investment, and chronically short of the indigenous labor force the conquistadors had counted on exploiting. Most colonists ended up working small subsistence farms themselves, which over time produced a relatively egalitarian rural society that historians often credit for Costa Rica’s later political stability.

Meanwhile, a few hours’ walk to the west, another settlement was slowly taking shape.

The rise of San José in the 18th century

San José began as a humble dispersal of farms in the Aserrí Valley. In 1736 — some sources say 1737 or 1738 — Spanish authorities ordered the scattered residents to consolidate around a small chapel dedicated to Saint Joseph (San José in Spanish). The original name was Villa Nueva de la Boca del Monte, but the chapel’s patron saint eventually gave the town its modern name.

For decades it was an unremarkable settlement. The turning point came in 1782, when the Spanish government opened the Factoría de Tabacos — a state-run tobacco monopoly factory — in San José. Tobacco farming had taken root in the surrounding hills in the late 1600s, and the factory turned the town into the commercial hub of Costa Rica’s tobacco trade. Money flowed in. Merchants set up shop. Population grew. By the census of 1815, San José had around 11,500 residents and had quietly surpassed Cartago in wealth.

The setup

By the time independence arrived, Costa Rica had two centers of gravity: Cartago held the political authority of the Crown, but San José held the money. The two cities had been quietly drifting apart for forty years — and once Spain was out of the picture, the gap turned into a fault line.

In 1813, Costa Rica’s representative to the Spanish Cortes in Cádiz — a priest named Florencio del Castillo — secured the title of “city” for San José. The title was briefly revoked when Ferdinand VII annulled the Cortes’ work, then restored in 1820. None of this seemed particularly dramatic at the time. Within three years, it would matter enormously.

Independence and the question nobody had answered

On September 15, 1821, Central America declared independence from Spain. The news reached Costa Rica in mid-October, carried by horseback along the colonial road from Nicaragua. There was no fighting and no Spanish authority to overthrow — the colonial government simply ceased to exist. Cartago, as the longstanding capital, became the seat of the new provisional government almost by default.

The trouble was that independence raised a question the colony had never had to consider: what now?

Two answers emerged, and they split the Central Valley right down the middle.

The Imperialists

Conservative landowners and the colonial aristocracy. Wanted Costa Rica to join the new Mexican Empire of Agustín de Iturbide, preserving the social hierarchy and protecting their privileges under a familiar monarchical structure.

Cartago · Heredia

The Republicans

Emerging merchants, tobacco traders, and a younger generation of liberal reformers. Wanted full independence as a republic — no king, no empire, no return to colonial structures dressed up in new clothes.

San José · Alajuela

Through 1822 the four cities argued and negotiated. A “Pact of Concordia” tried to keep everyone working together. It didn’t hold.

The Battle of Ochomogo, April 5, 1823

On March 29, 1823, a Cartago landowner named Joaquín de Oreamuno y Muñoz de la Trinidad led a group of imperialist sympathizers in seizing the army barracks in Cartago. They declared that Costa Rica would join the Mexican Empire, with a formal ceremony of allegiance set for April 6.

San José and Alajuela responded by appointing a young officer named Gregorio José Ramírez to lead the Republican militia. On April 4, Ramírez sent an ultimatum to the imperialists. It was ignored.

The next morning, the two armies met at the Cerro de Ochomogo — a high ridge in the mountains between San José and Cartago, on the route that traders, mule trains, and travelers had used for two centuries. The Republicans had roughly equal numbers but better organization. The imperialists had artillery inherited from the Spanish garrison and some cavalry.

“The Republicans won the battle and San José became capital of the country.” — what nineteenth-century histories tend to render in a single sentence took, in practice, just a few hours of fighting and about twenty lives.

The fighting was brief. By the time the smoke cleared, the imperialists had been routed and roughly twenty men were dead. The Republican forces marched into Cartago that same day. The provisional government was reorganized, and the capital was transferred to San José.

The historical irony

Word traveled slowly in 1823. The men who fought and died at Ochomogo over whether to join the Mexican Empire didn’t yet know that Agustín de Iturbide had already abdicated on March 19 — two weeks before the battle — and that the empire they were fighting for no longer existed.

Not quite settled: the Ley de la Ambulancia (1834)

If the story ended at Ochomogo, this would be a tidy article. It doesn’t.

Cartago had been the capital for 260 years. Its citizens — and the citizens of Heredia and Alajuela — were not willing to let San José simply absorb that status forever. For a decade the rivalry simmered in legislative chambers and newspaper editorials. Then, in 1833, the Cartago faction got their man into power: José Rafael de Gallegos y Alvarado, a Cartago-born merchant, was elected Head of State.

In March 1834, the legislature — operating under intense regional pressure — passed the Ley de la Ambulancia (the “Ambulance Law” or “Wandering Law”). The law required the seat of government to rotate every four years between the four major cities of the Central Valley: Alajuela, Heredia, Cartago, and San José.

In May 1834, the entire government — legislative, executive, and judicial — packed up its files and moved to Alajuela.

It went badly. Alajuela hadn’t been built to host a national government. Buildings were inadequate, legislators struggled to reach quorum (one historian noted that “the deputies couldn’t be bothered to ride a mule to Alajuela”), and a San José newspaper called La Tertulia mercilessly mocked the whole arrangement. Within a year the Head of State had resigned.

The War of the League and the consolidation of San José

In March 1835, the legislature elected Braulio Carrillo Colina — a sharp-minded San José lawyer and reformer — as the new Head of State. Carrillo’s priority was to end the rotating-capital nonsense and govern from a proper administrative center.

In August 1835 he repealed the Ley de la Ambulancia and proposed a compromise: the capital would move to a neutral village called San Juan del Murciélago (modern-day Tibás), located between San José and Heredia. While its buildings were being constructed, the executive would sit in San José and the legislature in Heredia.

The other three cities rejected the compromise outright. On September 26, 1835, Cartago renounced Carrillo’s government and named a coffee grower named Nicolás Ulloa Soto as their alternative Head of State. Alajuela joined within days. Heredia followed. The three cities formed the Liga de las Tres Ciudades — the League of Three Cities — and declared war on San José.

This was the Guerra de la Liga, Costa Rica’s second civil war. In early October the League’s combined militias, roughly 4,300 men, laid siege to San José with about 1,000 defenders inside.

On October 9, the Cartago militia attacked San José from Curridabat, carrying the statue of the Virgen de los Ángeles as their standard. They were repulsed. Over the next two and a half weeks, Carrillo’s smaller but better-organized force — led by General Antonio Pinto Soares — counterattacked. On October 28, they crossed the Río Virilla and broke the besieging armies in a series of sharp engagements. Heredia and Alajuela fell that same night. Cartago surrendered shortly after.

The war was over in roughly two weeks. San José had won — again — and this time the matter was settled for good.

Costa Rica’s capital timeline

1563
Cartago founded

Juan Vázquez de Coronado establishes the first permanent Spanish settlement in Costa Rica. Cartago becomes the colonial capital and will hold that status for 260 years.

1736
Villa Nueva de la Boca del Monte

Spanish authorities consolidate scattered farms in the Aserrí Valley around a small chapel dedicated to Saint Joseph. The settlement will eventually be called San José.

1782
Tobacco factory transforms San José

The Crown’s tobacco monopoly opens its Costa Rican factory in San José. The town becomes Costa Rica’s commercial hub and begins to economically outgrow Cartago.

1821
Independence from Spain

On September 15, Central America declares independence. Costa Rica’s four main cities split between Imperialists (Cartago, Heredia) and Republicans (San José, Alajuela).

1823
Battle of Ochomogo — capital moves to San José

On April 5, Republican militias under Gregorio José Ramírez defeat the Cartago imperialists on the Ochomogo ridge. The capital is transferred to San José. About 20 men die in the battle.

1834
The Ley de la Ambulancia

The legislature passes a law requiring the capital to rotate every four years between Alajuela, Heredia, Cartago, and San José. Government moves to Alajuela in May. Chaos ensues.

1835
War of the League

Braulio Carrillo repeals the law. Cartago, Alajuela, and Heredia revolt. After two weeks of fighting, San José’s smaller army defeats the combined League of Three Cities. The capital question is permanently settled.

1838
Independence from the Federation

On November 15, Carrillo formally separates Costa Rica from the Federal Republic of Central America. San José is now the capital of a fully sovereign nation.

What this history means for travelers today

San José is one of the youngest national capitals in Latin America — younger than the United States, younger even than the city of Houston. That youth is visible everywhere if you know where to look. Unlike Mexico City, Lima, or Cartagena, San José has almost no Spanish colonial architecture. The city you walk through today was largely built in the late nineteenth and early twentieth centuries on the strength of coffee wealth: the National Theatre (1897), Barrio Amón, the Central Park, and the grand Belle Époque facades along Avenida Central.

Cartago, meanwhile, sits 40 minutes away and feels its age in a quieter way. The Basílica de Nuestra Señora de los Ángeles — home of the Virgen de los Ángeles statue that was carried into battle in 1835 — remains Costa Rica’s most important pilgrimage site, drawing roughly two million walking pilgrims every August 2nd. The ruins of the old parish church (Las Ruinas), destroyed by earthquakes, sit in the city center as a reminder of what the colonial capital used to be.

Worth doing

If you’re spending a day or two in San José, a half-day trip to Cartago is one of the most underrated short excursions in the Central Valley — especially if you pair it with the Orosí Valley or a morning at Irazú Volcano. You’re tracing the actual geography of how the country was made.

The Ochomogo ridge itself is still there too, of course. The Pan-American Highway crosses it as it climbs out of the Central Valley toward Cartago. If you’ve driven from San José to the Caribbean coast or to Turrialba, you’ve passed directly over the site of Costa Rica’s first civil war — almost certainly without realizing it.

San José: capital since 1823 Cartago: capital 1563–1823 Battle of Ochomogo: April 5, 1823 Ley de la Ambulancia: 1834–1835 Settled for good: October 1835
• • •

Frequently asked questions

When did San José officially become the capital of Costa Rica?

San José officially became the capital in 1823, immediately following the Republican victory at the Battle of Ochomogo on April 5 of that year. The capital had previously been Cartago.

What was Costa Rica’s capital before San José?

Cartago was the capital of Costa Rica from its founding in 1563 until 1823 — a span of 260 years. It was the seat of Spanish colonial authority throughout the entire colonial period.

Why was the capital moved from Cartago to San José?

The move came out of the political split that followed independence from Spain in 1821. Cartago’s conservative elite wanted Costa Rica to join the Mexican Empire, while San José’s merchant class favored full republican independence. The 1823 civil war settled the question militarily, and the new Republican government moved its capital to its own base of power.

Was San José really only the capital because it won a war?

Essentially, yes — twice. The Battle of Ochomogo in 1823 transferred the capital from Cartago to San José, and the War of the League in 1835 prevented the other three Central Valley cities from taking it back. Both wars were short (a single battle and roughly two weeks, respectively) and produced relatively low casualties, but they decisively determined where Costa Rica’s political center would sit.

How old is San José as a capital city compared to other Latin American capitals?

San José is one of the youngest national capitals in Latin America. Mexico City has been a capital since 1521, Lima since 1535, Bogotá since 1538, and Santiago since 1541. San José only took the title in 1823, which is part of why the city has almost no Spanish colonial architecture — its grand buildings come from the coffee boom of the late nineteenth century instead.

Can you visit the Ochomogo battlefield today?

There is no formal battlefield park or monument at the site, but the Cerro de Ochomogo is still a recognizable geographical feature on the ridge between San José and Cartago. The Pan-American Highway passes directly through the area. Most travelers cross it without realizing what happened there.