The first gymnasium in Bosnia and Herzegovina was established in 1879 in Sarajevo, capital of the Austro-Hungarian Condominium of Bosnia and Herzegovina. Mostar, the largest city of the Herzegovina region in the south of the Condominium, was by then a developed education centre, second only to the capital. It had a merchants' school, 18 primary schools (two secular schools, one Orthodox, one Catholic girls' school, 4 Muslim boys' schools and 10 Muslim girls' schools), a private German school and a kindergarten. None of the schools, however, prepared students for a higher education, forcing parents to send their minor children to Sarajevo.
In February 1893, the local branch of the Serbian Orthodox Church appealed to the National Government of Bosnia and Herzegovina. The government was concerned that the student body would be too small, expecting Muslims (the most numerous religious group in Mostar) not to be interested. The Orthodox clergymen thus pointed out that their desire was shared by Catholics. The National Government would only allow a lower gymnasium, but the superior Ministry of Finance of Austria-Hungary ordered that the new school be a full gymnasium and opened within 1893. Teachers' and principal's posts were advertized throughout the entire Austria-Hungary.
The school was ceremoniously opened on 26 October 1893 and, despite concerns raised by the National Government, it immediately enrolled members of all of Bosnia and Herzegovina's religious groups: Orthodox Christians, Catholics, Muslims and Jews. The first teaching staff was formed by three teachers, including the Slovene philologist Martin Bedjanič (1855-1931), whose assigned subjects were Bosnian and Latin and who also served as he first principal, and the biologist Antun Pichler (1862-1922), who taught Natural Sciences. They were joined the same year by a Catholic and an Orthodox religion teacher, by their Muslim counterparts the following year, and finally by a Jewish religion teacher. Until the present building became functional in 1898, classes were held in a leased house of the city councillor Husaga Komadina (brother of the future mayor Mujaga Komadina). Besides instructions in Islam, Serbian Orthodoxy, Roman Catholicism or Judaism, the compulsory subjects were Bosnian, German, Latin, Greek (or, alternatively, Classical Arabic for Muslim students), Geography and History, Mathematics, Natural Sciences, Philosophical Propaedeutics, Free-Hand Drawing, Penmanship and Gymnastics. Singing, French, Italian, Stenography and Gusle were optional subjects.
The Minister of Finance Béni Kállay took it upon himself to provide the gymnasium with a proper building. The first design was offered by the Czech architect Max David in 1897, but Kállay turned it down and gave the project to another Czech architect, František Blažek. The first half of the gymnasium was completed in 1898 and the second in 1902. Featuring Andalusian and Mamluk elements as an example of Moorish Revival architecture, the building is the result of Austro-Hungarian desire to promote Bosnian national identity while avoiding its association with either the Ottoman Empire or the growing pan-Slavic movement by creating an "Islamic architecture of European fantasy". The gymnasium is thus of historic value and is considered a national monument.
The first students included the geographer Jevto Dedijer (whose lowest grade was in Geography), the poet Osman Đikić (awarded for performance but later expelled for political activity) and the journalist Risto Radulović. The first girls to enroll the school, in 1905, were Jewish sisters Marija (1894-1987) and Berta Bergman (1891-1945), later a university professor and a physician respectively. Marija was, for a time, also employed as German Language teacher at the gymnasium.
The school belonged to the most renowned and academically prestigious educational institutions in Yugoslavia, and was possibly the most reputable school in Bosnia and Herzegovina. It numbered 2,000 students, including Bosniaks, Bosnian Croats and Bosnian Serbs alike. The school alumni include the historian Vladimir Ćorović, the philosopher and poet Dimitrije Mitrinović, and the writer Predrag Matvejević. The Communist activist and future Prime Minister of Bosnia and Herzegovina Avdo Humo also attended the gymnasium before being evicted in November 1931 due to "committing political transgressions at school".
The gymnasium was considerably damaged due to shelling during the Bosnian War, particularly so during the Croat–Bosniak War, being located at the front line. Following the war, classes for Bosnian Croat students were held on a single floor of the ruined building, with Bosniak students returning in 2004. Renovation of the gymnasium started the same year and was completed in 2009.
Gimnazija Mostar presently operates under two separate secondary school curricula and in two completely mutually intelligible language varieties, Bosnian and Croatian, with sports and a few classes combined. Though it was originally intended to fully integrate subjects or at least the science ones (Biology, Chemistry, Information Technology, Mathematics and Physics), the idea of unification was fiercely opposed by local politicians, especially Croat officials who felt that their national identity was being threatened. Nevertheless, integration has been achieved to a certain extent in what has been called a "rare social experiment". Students themselves mostly welcomed the desegregation.
Located in the very centre of the town, next to the former front line which has divided the town into two spheres since the war, it is one of the first schools in post-war Bosnia and Herzegovina in which the integration of students from different ethnic groups was implemented, and the only such school in Mostar.
As of 2013, the school is attended by about 360 Bosniaks and about 290 Bosnian Croats. There are two six-hour sessions a day, the first session reserved for third- and fourth-year students, and the second session for younger students. Students from both groups mingle during recess, with considerable intercommunal flirting reported. Nationalist politicians still promote the idea of segregation, with the education minister Greta Kuna declaring that "apples and peaches should not mix".
In 2006, Queen Noor of Jordan, president of the United World Colleges, opened the United World College in Mostar, which is housed on the gymnasium's third floor.