In the pre-Roman era, the hills in the Piran area were inhabited by Illyrian Histri tribes who were farmers, hunters and fishermen. They were also pirates who disrupted Roman trade in the northern Adriatic. The Piran peninsula was incorporated into the Roman Empire in 178 and 177 BC and settled in the following years with rural homes (villae rusticae).
The decline of the Roman Empire, from the 5th century AD onward, and incursions by the Avars and Slavs at the end of the 6th century, prompted the Roman population to withdraw into easily defensible locations such as islands or peninsulas. This started local urbanisation and by the 7th century, under Byzantine rule, Piran had become heavily fortified. Despite the defences, the Franks conquered Istria in 788 and Slavs settled in the region. By 952, Piran had become a part of the Holy Roman Empire.
The earliest reliable records of the area are in the 7th century work Cosmographia by an anonymous cleric of Ravenna. The name of the town most probably originates from the Greek "pyrranos", which means "red", because of the reddish flysch stones commonly found in the town's area. Some historians also refer it to "pyros", meaning fire, due to ancient lighthouses which were supposed to be on the edge of the marine.
From 1283 to 1797, the town became part of the Republic of Venice, where it was governed in a semi-autonoumous way, with a council of local noblemen assisting the Venetian delegate. Several enemy (e.g. from the Republic of Genoa) and pirate assaults were repelled during the late Middle Ages; a great pestilence hit the town in 1558, killing about two thirds of the population. The last decades of Venetian rule were marked by decadence, due to the competition with the nearby Austrian port town of Trieste.
The town was annexed to Austrian Empire in 1797; but during the years from 1806 to 1814, when it was ceded to Napoleonic Empire. On 22 February 1812, the Battle of Pirano was fought between a British and a French ship of the line in the vicinity of Piran. This was a minor battle of the Adriatic campaign of the Napoleonic Wars. The French Rivoli had been recently completed at Venice. The French naval authorities intended her to bolster French forces in the Adriatic, following a succession of defeats in the preceding year. Captain John Talbot of HMS Victorious arrived off Venice in mid-February and blockaded the port. When Rivoli attempted to escape under the cover of fog, Talbot chased her and forced her to surrender in a five-hour battle, Rivoli lost over half her crew as either wounded or dead. This was the only battle ever fought in the sea nowadays belonging to Slovenia.
At the end of the 19th century and the beginning of the 20th century, Piran was an Austro-Hungarian city with over 12,000 inhabitants, larger than the nearby Koper. It was a flourishing market and spa town with good transport connections. The first trolleybus line in the Balkans was introduced to public service on 24 October 1909 in Piran. In 1912, it was replaced by a tramway that operated on the same route till 1953.
After the First World War, together with Trieste and all Istria, the town was ceded to Italy. There were no particular events in those years, until Italy entered the Second World War in 1940. With the defeat of the Axis powers and the rise of Tito's rule, Piran was assigned to the Free Territory of Trieste, Zone B, under Yugoslavian administration. The town was annexed to Yugoslavia in 1954, according to the London Memorandum signed together with Italy. A significant part of Piran's population chose to emigrate to Italy or abroad in the final phase of the Istrian exodus, rather than stay in socialist Yugoslavia. The annexation to Yugoslavia was finally ratified with the Osimo Treaty in 1975, signed as well from Italy. Since 1991 on, Piran is part of the independent Slovenia.
On 24 October 2010, Slovenia became the first country of former communist Europe to elect a black mayor. The physician Peter Bossman, who came from Ghana in the late 1970s, was elected mayor of Piran. He officially took office at the first constitutional meeting of the municipal council on 12 November 2010, succeeding Tomaž Gantar. He represents the Social Democrats.
Piran is the birthplace of composer and violinist Giuseppe Tartini, who played an important role in shaping its cultural heritage. The town's main square, Tartini Square (Slovene: Tartinijev trg, Italian: Piazza Tartini), is named after him. In 1892, the 200th anniversary of his birth, a monument to Tartini was erected in Piran. Venetian artist Antonio Dal Zotto was commissioned to create a larger-than-life bronze statue, which was mounted on its pedestal in 1896. The statue dominates the square, overlooked by the Cathedral of Saint George. The painter Cesare Dell'Acqua was also born in Piran.
Piran is the seat of the Euro-Mediterranean University of Slovenia (EMUNI), founded in 2008 as one of the cultural projects of the Barcelona Process: Union for the Mediterranean. The Piran Coastal Galleries, a public institution encompassing a group of six public contemporary art galleries, is based in Piran.
Musical Evenings of Piran have taken place for decades in Greyfriars Franciscan monastery's atrium, one of the most beautiful cloister atriums in the Slovenian Littoral, which has good acoustics. The municipality's festival is 15 October, which celebrates the foundation of the first Slovenian partisan naval detachment, named Koper, in 1944. This was the first Slovenian naval unit.
Piran is situated at the tip of the Piran peninsula on the Gulf of Piran. It borders Croatia to the south, and the municipalities of Izola and Koper to the east and faces Italy across the Gulf of Trieste and the Adriatic Sea. The highest point, Baretovec pri Padni, is 289 metres high.
To the east of the town, along the northern coastline (in the direction to Strunjan) there is a small tourist settlement named Fiesa. Piran and Fiesa are connected by a promenade along the beach. Piran has a humid subtropical climate with warm summers and cool rainy winters. Snow is rare (usually 3 days per year, almost always in traces). There are 22 days a year with maximum temperatures of 30 °C (86 °F) or higher; on one day a year the temperature does not exceed 0 °C (32 °F). Fog appears about 4 days per year, mainly in winter.
The municipality had 17,800 inhabitants in 2010 (399 per square kilometre), and covers an area of 45 square kilometres (17.4 sq mi). The municipality is bilingual, both Slovene and Italian are official languages. According to the Austrian language census of 1910, there were 7,379 inhabitants in the town proper, 95.97% Italians and 0.09% Slovenes. In the surrounding countryside, included within the municipal limits, the population was mixed, both Italian and Slovene, with some villages (such as Sveti Peter and Padna) which were almost entirely Slovene, and others (such as Sečovlje and Seča) that were almost exclusively Italian-speaking. As a whole, the 85.1% of the population of the Piran municipality were Italian speakers, and 15.2% were Slovenes. In 1945, the town proper had 5,035 inhabitants, 91.32% Italian and 8.54% Slovene speakers. In 1956 there were 3.574 inhabitants, 67.6% Slovene and 15.5% Italian. After 1947, the ethnic composition changed radically due to the exodus of Italians to Italy and their replacement by Slovene settlers, both from other areas of Slovenian Istria and from interior areas of the country.
Piran was heavily influenced by the Venetian Republic and Austria-Hungary, therefore the monuments differ greatly from those in inner parts of Slovenia. The Piran town walls were constructed to protect the town from Ottoman incursions; many parts of the town walls from different eras remain, and are of interest to tourists. In the middle of the town is the Tartini Square, with a monument in memory of Giuseppe Tartini. Nearby are located various important buildings, such as Tartini’s house, first mentioned in 1384 and one of the oldest in town, the Municipal Palace, Loggia and Benečanka, among others. On the hill above the town is the biggest and most important church, the Church of Saint George, with a Franciscan monastery nearby.
There is an international airport and a marina in the vicinity of the town. The medium-wave transmitter of Radio Koper is in Piran. It transmits on 1170 kHz and has a 123.6-metre-tall guyed mast with cage antenna. The town is connected with Koper, Izola, Portorož (the location of the airport), Sečovlje and Lucija by a cheap bus line. The lines of other coastal settlements operate mostly during the tourist season.
The first trolleybus line in the Balkans entered public service on 24 October 1909 in Piran, then part of Austria-Hungary. It ran from Tartini Square along the coast and the shipyard to Portorož and Lucija. The town authorities bought five trolleybuses manufactured by Austrian company Daimler-Motoren-Gesellschaft. In 1912, it was replaced by a tram system that operated until 1953, when it was superseded by buses.
Pod Obzidjem Stadium (Slovene: Stadion pod obzidjem) is a multi-purpose stadium in Piran. It is used for football matches and is the home ground of football team NK Portorož Piran. The stadium currently holds 750 spectators, 500 of them can be seated.