Consulates in extraterritorial jurisdictions
In countries outside of its borders, a foreign power often has extraterritorial rights over its official representation (such as a consulate). If such concessions are obtained, they are often justified as protection of the foreign religion (especially in the case of Christians in a Muslim state) such as the ahdname or capitulations granted by the Ottoman Sultan to commercial Diasporas residing in the Ottoman Empire. The Sultan did not see this agreement as a bilateral agreement between equals, but merely as acknowledging the nation of foreigners living within his territory and offering them privileges similar to those given to non-Ottoman subjects. However, the European states viewed the ahdname as formal and official and therefore had difficulty enforcing the privileges to their satisfaction on many occasions.
Historical examples 
A few examples:
- In 1261, the Genoese assisted Byzantine Emperor Michael VIII Palæologus in reconquering Constantinople and were rewarded with Smyrna and Pera as well as a Black Sea trade monopoly. They rapidly developed markets along the Black Sea's shores, the principal one being Caffa, and carried on a brisk trade, exporting mainly wine, oil, woolens and silks, and importing skins, furs, corn and Persian goods. A consulate general of the empire of Gazaria was established as the local government of these colonies. Some Genoese moved to Caffa where they remained a minority, but were able to govern the city to suit their interests because of the presence of the Genoese consul. The Genoese also had a consular presence in Chilia as early as 1322 where the consul served the interests of the merchants trading grain, honey, and other goods. Chilia and Caffa are examples of places where a wide variety of merchants came to trade and where consuls would have been used. The Genoese had a consul in Alexandria “who was empowered to settle disputes brought by a Saracen against a Genoese” after the agreement between Genoa and Mamluk in 1290.
- In 1453 Sultan Mehmed II laid siege to Constantinople thus ending the Byzantine Empire. However, the Genoese merchants of Galata declared their neutrality before the battle and Mehmed II restored the trading rights to the merchants through an ahidnâme after capturing the city. Mehmed II “[left] intact the Genoese community council of Pera, grant[ed] the district legal and some political autonomy, exempt[ed] its Genoese inhabitants from all extraordinary taxes and forced conversion, and concede[d] its alien residents the freedom to trade and travel in the Ottoman domains.” This is not unprecedented, but was probably one of the most important examples of the ahdname being granted.
- In 1855, Sir John Bowring signed a new treaty whereby Siam agreed to the appointment of a British consul in Bangkok and to that official exercising full extraterritorial powers. British subjects were permitted to own land in certain defined districts, customs and port dues and land revenues were fixed, and many new trade facilities were granted. This important arrangement was followed at intervals by similar treaties with the other powers, the last two being those with Japan in 1898 and Russia in 1899. A later convention established a second British consular district in northern Siam, while Britain and France both appointed vice-consuls in different parts of the country. Thus Westerners in Siam (the Chinese had no consul) could only be tried for criminal offences, or sued in civil cases, in their own consular courts. A large portion of the work of the foreign Consuls, especially the British, was consequently judicial and in 1901 the British government appointed a special judge and an assistant judge to this post. Meanwhile, trade steadily increased, especially with Great Britain and the British neighbouring colonies of Hong Kong and Singapore.
In the small Italian concession in Tientsin (a treaty port, now Tianjin), the Consul was in charge of the entire local administration. A long list of French consuls-general in Shanghai served as both overseers of the French concession in this Chinese port as well as presidents of the metropolis's Municipal Council. This arrangement lasted from January 1848 until 15 May 1946 (shortly after the 28 February formal restoration of power from France to China).
Consular Courts 
In places where consuls had extraterritorial powers consular courts would also be established to handle civil and criminal cases against citizens and subjects of that country. The British had the widest system of consular courts run by the Foreign Office. British consular courts could be found in Africa, the Ottoman Empire, Egypt, China, Japan and Siam.
In 1865, the British Supreme Court for China and Japan was established in Shanghai, China as a first instance consular court for cases in the Shanghai region as well as an appellate court for cases heard by consular courts in the rest of China and Japan. In 1879, a British Court for Japan was established in Yokohama to replace the Kanagawa consular court to hear first instance cases for Yokohama region as well as to act as an appellate court for cases from consular courts in other Japanese cities.
In China and Japan under the unequal treaties many countries established consular courts in cities open to foreign trade. In Japan extraterritoriality came to an end on 4 August 1899 and the consular courts closed soon after that after finalising pending cases. In China consular courts operated up until the 1940s when extraterritoriality for most nations came to an end then. In 1906, the United States established the United States Court for China modelled on the British Supreme Court for China and Japan.