According to tradition, Marino, a Christian stonecutter from Dalmatia, took refuge (early 4th cent.) on Mt. Titano (2,300 ft/701 m), the chief geographical feature of present-day San Marino. By the mid-5th cent., a community was formed; because of its relatively inaccessible location and its poverty, it has succeeded, with a few brief interruptions, in maintaining its independence. In 1631 its independence was recognized by the papacy. In 1849, San Marino gave refuge to Garibaldi, the Italian patriot and soldier. Italy and San Marino signed a treaty of friendship and economic cooperation in 1862 (renewed and expanded several times). Volunteers from San Marino served with the Italians in World Wars I and II; Allied aircraft bombed the republic in 1944.
Following a period of Communist rule (1947–57), a coalition of Christian Democrats and Social Democrats came to power. In 1973, the Social Democrats left the coalition and were replaced by the Socialists and the tiny Movement for Statutory Liberties. In 1960 women were given the right to vote, and in 1973 they were granted the right to hold public office. A left-wing coalition led by the Communists ruled from 1978 to 1986, at which time the Communists joined with the Christian Democrats to form a new government. The coalition was reelected in 1988. The Communist party changed its name in 1990 to the Democratic Progressive party and continued in coalition with the Christian Democrats. In 1992, the Christian Democrats formed a new coalition with the Socialists; they remained in power following the 1993 and 1998. Governmental instability after the 2001 elections led to broad-based national unity government in 2003. In 2006 the Socialists and Democrats, a merger of the Socialists, former Communists, and others, won a plurality and formed a coalition government. Coalitions led by the Christian Democrats won the 2008 and 2012 elections. San Marino became a member of the United Nations in 1992.