The early history of Monaco is primarily concerned with the protective and strategic value of the Rock of Monaco, the area's chief geological landmark, which served first as a shelter for ancient peoples and later as a fortress. Part of Liguria's history since the fall of the Roman Empire, from the 14th to the early 15th century the area was contested for primarily political reasons. Since that point, excepting a brief period of French occupation, it has remained steadily under the control of the House of Grimaldi.
Grimaldi Man lived here from about 30,000 years ago.
According to the accounts of historian Diodorus Siculus and geographer Strabo, the area's first permanent settlers were the mountain-dwelling Ligures, who emigrated from their native city of Genoa, Italy. However, the ancient Ligurian language, which most likely was Indo-European, is not directly connected to the Italian dialect spoken by the modern inhabitants of Liguria, nor to the modern Monegasque language.
"According to some authorities, the Egyptians of the Eighteenth Dynasty, according to others, the early Phoenicians were the first commercial navigators," who found refuge in the Port of Monaco from the mistral of the sea. The Port and Rock of Monaco were consecrated by the Phoenicians in the name of their deity Melqart. After the Phoenicians, the Greeks, with their poetical imagination, rewrote the progress and conquests of the early Phoenicians as the journeys and labors of Hercules. 
During the 6th-century BC, Phocaeans from Massalia (modern day Marseille) founded the colony of Monoikos. The name of the colony derives from the local veneration of the Greek demigod Hercules, also later adopted by the Romans, who was said to have constructed the ancient path that passed through the region from Spain to Italy. The Roman emperor Julian also wrote of Hercules's construction of Monaco's port and a coastal road. The road was dotted with altars to Hercules, and a temple dedicated to him was established on the Rock of Monaco. The name Port Hercules was subsequently used for the ancient port. Monoeci meaning "Single One" or Monoikos meaning "Single House" could be a reference to Hercules or his temple, or the isolated community inhabiting the area around the rock.
According to the "travels of Hercules" theme, also documented by Diodorus Siculus and Strabo, both Greeks and native Ligurian people asserted that Hercules passed through the area.
After the Gallic Wars, Monoecus, which served as a stopping-point for Julius Caesar on his way to campaign in Greece, fell under Roman control as part of the Maritime Alps province (Gallia Transalpina).
The Roman poet Virgil called it "that castled cliff, Monoecus by the sea" (Aeneid, VI.830). The commentator Servius's use of the passage (in R. Maltby, Lexicon of Ancient Latin Etymologies, Leeds) asserts, under the entry portus, that the epithet was derived:
dictus autem Monoecus vel quod pulsis omnibus illic solus habitavit, vel quod in eius templo numquam aliquis deorum simul colitur.
"either because Hercules drove off everyone else and lived there alone, or because in his temple no other of the gods is worshipped at the same time."
No temple to Hercules has been found at Monaco (see also Lucan 1.405.), although the rocky ground and dense conurbation make future excavations unlikely.
The port is mentioned in Pliny the Elder's Natural History (III.v) and in Tacitus's Histories (III.42), when Fabius Valens was forced to put into the port (Fabius Valens e sinu Pisano segnitia maris aut adversante vento portum Herculis Monoeci depellitur).
Monaco remained under Roman control until the collapse of the Western Roman Empire in 476. The city was then under the domain of Odoacer until his fall at the hands of the Ostrogoths in the late 5th century. Monaco was recaptured by the Romans during the reign of Justinian in the mid-6th century and was held until its capture by the Lombards in the 7th century. Monaco then passed hands between the Lombards and Franks. Though these raids left the area almost entirely depopulated, the Saracens were expelled in 975, and by the 11th century the area was again populated by Ligurians.
In 1191, Holy Roman Emperor Henry VI granted suzerainty over the area to the city of Genoa, the native home of the Ligurians. On 10 June 1215, a detachment of Genoese Ghibellines led by Fulco del Cassello began the construction of a fortress atop the Rock of Monaco. This date is often cited as the beginning of Monaco's modern history.
As the Ghibellines intended their fortress to be a strategic military stronghold and center of control for the area, they set about creating a settlement around the base of the Rock to support the garrison; in an attempt to lure residents from Genoa and the surrounding cities, they offered land grants and tax exemption to new settlers.
The Grimaldis, descended from Otto Canella and taking their name from his son Grimaldo, were an ancient and prominent Guelphic Genoese family. Members of this family, in the course of the civil strife in Genoa between the Guelphs and Ghibellines, took refuge in Monaco, accompanied by various other Guelphic families, most notably the Fieschis.
Francesco Grimaldi seized the Rock of Monaco in 1297, starting the Grimaldi dynasty, under the sovereignty of the Republic of Genoa. The Grimaldis acquired Menton in 1346 and Roquebrune in 1355, enlarging their possessions. In 1338 Monegasque ships under the command of Carlo Grimaldi participated, along with those of France and Genoa, in the English Channel naval campaign. Plunder from the sack of Southampton was brought back to Monaco, contributing to the principality's prosperity.
Honoré II, Prince of Monaco secured recognition of his independent sovereignty from Spain in 1633, and then from Louis XIII of France by the Treaty of Péronne (1641). Since then the area has remained under the control of the Grimaldi family to the present day, except when under French control during the French revolution from 1793 to May 17, 1814, as part of the département of Alpes-Maritimes.
The principality was re-established in 1814, only to be designated a protectorate of the Kingdom of Sardinia by the Congress of Vienna in 1815 and the Treaty of Stupinigi in 1817. Monaco remained in this position until 1860, when by the Treaty of Turin, Sardinia ceded to France the surrounding county of Nice (as well as Savoy).
With the protectorate, that lasted nearly half a century, Italian was the official language of Monaco. The Monégasque dialect is closer to Ligurian than French, but influenced by both.
During this time there was unrest in the towns of Menton and Roquebrune, which declared independence, hoping for annexation by Sardinia and participation in the Italian Risorgimento. The unrest continued until the ruling prince gave up his claim to the two towns (some 95% of the country), and they were ceded to France in return for four million francs. This transfer and Monaco's sovereignty was recognised by the Franco-Monegasque Treaty of 1861.
Further information: France–Monaco relations
Designated as a protectorate of the Kingdom of Sardinia in 1815 by the Congress of Vienna after Napoleon's defeat, Monaco's sovereignty was confirmed by the Franco-Monegasque Treaty of 1861. France accepted the existence of the Principality of Monaco, but annexed 95% of its former territory (the areas of Menton and Roquebrune). Monaco's military defense since then has been the responsibility of France.
The Prince of Monaco was an absolute ruler until the Monegasque Revolution of 1910 forced him to proclaim a constitution in 1911.
The famous Casino of Monte Carlo opened in 1863, organized by the Société des bains de mer de Monaco, which also ran the Hotel de Paris. Taxes paid by the S.B.M. have been plowed into Monaco's infrastructure. Economic development was spurred in the late 19th century with a railway link to France.
In July 1918, a treaty was signed providing for limited French protection over Monaco. The treaty, written into the Treaty of Versailles, established that Monegasque policy would be aligned with French political, military, and economic interests. One of the motivations for the treaty was the upcoming Monaco Succession Crisis of 1918.
While Prince Louis II's sympathies were strongly pro-French, he tried to keep Monaco neutral during World War II but supported the Vichy French government of his old army colleague, Marshal Philippe Pétain.
Nonetheless, his tiny principality was tormented by domestic conflict partly as a result of Louis's indecisiveness, and also because the majority of the population was of Italian descent; many of them supported the fascist regime of Italy's Benito Mussolini.
On 11 November 1942, the Italian Army invaded and occupied Monaco causing a run on the casinos. Soon after in September 1943, following Mussolini's fall in Italy, the German Army occupied Monaco and began the deportation of the Jewish population.
Among them was René Blum, the prominent French Jew who founded the Ballet de l'Opera in Monte Carlo, was arrested in his Paris home and held in the Drancy deportation camp outside the French capital before being transported to the Auschwitz concentration camp, where he was later killed. Blum's colleague Raoul Gunsbourg, the director of the Opéra de Monte-Carlo, helped by the French Resistance, escaped arrest and fled to Switzerland. In August 1944, the Germans executed René Borghini, Joseph-Henri Lajoux and Esther Poggio, who were Resistance leaders. Under Prince Louis's secret orders, the Monaco police, often at great risk to themselves, warned in advance those people whom the Gestapo planned to arrest. The country was liberated, as German troops retreated, on 3 September 1944.
Prince Rainier III ascends to the throne following the death of his grandfather, Prince Louis II, in 1949.
The revised Constitution of Monaco, proclaimed in 1962, abolished capital punishment, provided for female suffrage, established a Supreme Court to guarantee fundamental liberties and made it difficult for a French national to transfer his or her residence there.
In 1993, Monaco became a member of the United Nations with full voting rights.
In 2002, a new treaty between France and Monaco clarifies that if there are no heirs to carry on the dynasty, the Principality will remain an independent nation, rather than be annexed by France. Monaco's military defence, however, is still the responsibility of France.
Prince Albert II succeeds his father Prince Rainier III in 2005.
Monaco's mild climate with historical sites and modern gambling casinos, make Monaco a popular tourism and recreation centre in the 21st century, with 4.1 tourists per residentent as of 2020.