The first trace of human presence in Porrentruy is a mesolithic tool that was found in the back yard of the Hotel-Dieu. Scattered, individual objects have also been found from the neolithic, the late Bronze Age and the Iron Age. The first known settlement in what became Porrentruy goes back to the Roman era. In 1983, the ruins of a Gallo-Roman temple were discovered in the cemetery on the north of town, and Roman coins were found there. Near the town, a kilometer long (0.6 mile) section of the Augst-Epomanduodurum (now Mandeure) Roman road was discovered.
In the back yard of the Hotel-Dieu the charred remains of a building from the 10th or 11th century were discovered. However, the first historical mention of the name occurs in 1136 as Purrentru. The name presumably comes from the Latin pons Ragentrudis (Ragentrud bridge). Ragentrud was the wife of the Frankish King Dagobert I. The German form of the name, Pruntrut may have a separate etymology from Bruntrutum, which means an abundant spring.
The first settlement was established in 1140 in the vicinity of Church of Saint-Germain, which was built in the Early Middle Ages. The Counts of Pfirt, who owned the region around Porrentruy, built a castle on a defensible hill and made it the capital of the Ajoie territory. A settlement (now known as the Faubourg de France) was founded at the foot of the castle, with another south on the opposite hill. The city wall was probably built before 1283 and surrounded the two settlements, but not the parish church of Saint-Germain.
In 1236 the Counts of Pfirt pledged the town to the Counts of Montbeliard, however, they retained their rights to the Ajoie until 1281 when they sold the territory to the Bishop of Basel. The Counts of Montbeliard refused to hand over Porrentruy, which led Bishop Henry of Isny to request support from King Rudolph I of Habsburg. After six weeks under siege, the Count relented and handed it over to the Bishop. On 20 April 1283, the king asked the Bishop of Basel to grant Porrentruy a town charter and make it a free Imperial city. While the Counts of Montbeliard retained some power in the town, their influence waned during the 13th century.
Financial difficulties forced the Bishop to sell the Ajoie (including Porrentruy) back to the lords of Montbeliard in 1386. But in 1461, the town once again became subject to the episcopal see. Because of the Reformation in Basel, the Bishopric moved its official headquarters to Porrentruy in 1527. Under Bishop Jakob Christoph Blarer von Wartensee, who reigned from 1575 to 1608, the town reached the apogee of its importance. In his time, many architectural projects, including expansion of the castle and the building of a Jesuit college, were undertaken. This period of prosperity ended in 1618 with the outbreak of the Thirty Years War. Porrentruy was repeatedly occupied, besieged, and plundered.
The first parish church of Saint-Germain was replaced in the 13th century by a new building, which underwent several renovations. The Church of Saint-Pierre was completed in 1349 and became the parish church in 1475. The cathedral chapter was established in 1377. Several religious orders were active in the city, including the Jesuits who built their college in 1591. In addition to the Jesuits other orders included the Ursulines (1619), the Sisters of the Annonciade (permanently established in 1646) and the Capuchins (1663).
The first uprising against the Bishops power was under the Comite de la Commune de Porrentruy on 20 August 1790, but they were unable to expel the Bishop. However, on 27 April 1792, French Revolutionary troops invaded the city and drove the Bishop out. Porrentruy became the capital of a dependent republic, which was then incorporated into France in 1793 as the Departement du Mont-Terrible. In 1800, this department was incorporated into the Departement du Haut-Rhin as a sub-departement. During the War of the Sixth Coalition against Napoleon, Allied troops entered Porrentruy on 24 December 1813. Following their liberation, the future of this former episcopal seat was uncertain. The government divided into two parties, the Episcopal party that sought the return of the prince bishop as the head of a Swiss canton, while the French party wanted to retain the current secular government. However, soon after the fall of Napoleon, the municipality was given to the Canton of Bern (in 1815) to compensate for the loss of the Canton of Vaud, which had become a separate canton in 1803.
Both factions, the religious and the secular, retained power in the town in the following years. The political life in the 19th century was characterized by the severe conflict between Liberal-Radicals and the Catholic Conservatives. The secular side gained power in 1860, when the mayor, Joseph Trouillat, was forced out of office. The Radicals retained the mayors office and a majority of the town council from 1860 until 1972.
Until World War I, Porrentruy was the cultural center of the region and had a larger population than Delemont. However, with the increase in automobile traffic, its situation on the edge of the country became a liability and caused economic stagnation. In the second half of the 20th century, tensions between the French-speaking minority in the Canton of Bern and the German-speaking majority led to the creation of the new Canton of Jura on January 1, 1979. To the chagrin of the inhabitants of Ajoie, Delemont was chosen as the cantonal capital.
Porrentruy has an area of 14.75 km2 (5.70 sq mi). Of this area, 5.08 km2 (1.96 sq mi) or 34.4% is used for agricultural purposes, while 5.91 km2 (2.28 sq mi) or 40.1% is forested. Of the rest of the land, 3.64 km2 (1.41 sq mi) or 24.7% is settled (buildings or roads), 0.12 km2 (30 acres) or 0.8% is either rivers or lakes and 0.03 km2 (7.4 acres) or 0.2% is unproductive land.
Of the built up area, industrial buildings made up 1.7% of the total area while housing and buildings made up 10.7% and transportation infrastructure made up 7.3%. Power and water infrastructure as well as other special developed areas made up 3.5% of the area while parks, green belts and sports fields made up 1.5%. Out of the forested land, 38.8% of the total land area is heavily forested and 1.2% is covered with orchards or small clusters of trees. Of the agricultural land, 22.0% is used for growing crops and 12.1% is pastures. Of the water in the municipality, 0.2% is in lakes and 0.6% is in rivers and streams.
The municipality lies on both sides of the Allaine River, in Ajoie (the bulge in the northwest corner of Switzerland that extends into France) at the foot of the Jura Mountains on the north. In addition to the wide valley of the Allaine itself, it includes the watershed of the Creux-Genat River, that flows down from the peaks of La Banne (511 m [1,677 ft]) and La Perche (526 m [1,726 ft]). In the north, the municipality includes the hills and forests of the Petit Fahy (543 m [1,781 ft]) und Grand Fahy (570 m [1,870 ft]). The highest point in the municipality is the ridge that divides it from the municipality of Bure at 580 m (1,900 ft).
In the course of the 19th century, Porrentruy developed from a trading center to an important industrial town, with traditional industries such as watchmaking, shoemaking, and textiles. In the 20th century, other important industries were added, notably metalworking, machine manufacturing, electronics, and furniture building. Agriculture is no longer a major factor in the labor market of the municipality.