According to tradition San Marino, part of the Roman Empire, becomes an independent state, successively known as Land of San Marino, Free City of San Marino, and finally Republic of San Marino. In 1243 the republic gets its first constitution. The positions of Captains Regent (Capitani Reggenti) are established to be the joint heads of state. Every six months, parliament elects two Captains Regent to be the heads of state. The regents are chosen from opposing parties so they can keep an eye on each other. They serve a 6-month term. The country remains independent until now, although it is occupied by papal forces between 1739 and 1740 and by German, successively British forces in 1944.

Since the constitution of 1925 San Marino is a parliamentary democracy. This doesn't prevent the fascist Partito Fascista Sammarinese (Sanmarinese Fascist Party, PFS) to rule the country from 1930 until 1944. From 1945 until 1957 San Marino is governed by a coalition of the Partito Comunista Sammarinese (San Marino Communist Party, PCS) and Partito Socialista Sammarinese (San Marino Socialist Party, PSS), but since 1957 the government is dominated by the Partito Democratico Cristiano Sammarinese (San Marino Christian Democratic Party, PCDS). Since 1973 the country is governed by a coalition of the PCDS and the PSS. Women are granted the right to vote as late as 1960.

The PSS leaves the coalition in 1977 and in 1978 it can form a government with the PCS and dissident socialists. This coalition collapses in 1986. The PDCS forms a coalition with the PCS, Europe's first-ever coalition of christian democrats and communists (since 1990 the Partito Progressista Democratico Sammarinese (San Marino Progressive Democratic Party, PDPS). In 1992 the PDCS and the PSS revive their coalition. After the 2001 elections the PSS, the PDCS and the PDPS-succesor Partito dei Democratici (Party of Democrats, PdD) form a coalition. The head of government is the Secretary of State of Foreign and Political Affairs. This position is held since 2002 by Fiorenzo Stolfi of the PSS.