Just across the river from the sleepy old-town of central Ljubljana – a delicate maze of cobbled streets, medieval fortifications and colourful churches that characterise the many cities once occupied by the former Austro-Hungarian Empire – lie the dozen or so dilapidated buildings that make up what has become known as Slovenia’s second capital. On first glance, it is hard to believe it’s actually occupied. There are no signs directing visitors to its gates: the rubbish-strewn streets are eerily empty in the daylight, the graffiti covering the walls unread. But after dark, it becomes the focal point of the country’s alternative culture scene.

This is Metelkova Mesto – one the largest, and arguably most successful, urban squats in Europe. Sprawled across 12,500 sq m of an abandoned army base, the self-proclaimed city has become the leading centre of underground music and art in the region. Vivid, cracked-tile mosaics adorn the walls of the complex’s galleries and studios; rusty sculptures, fashioned from broken bike frames and upturned oil drums, cover its concrete gardens. And at night thousands of students and artists congregate to revel in its streets and bars.

Every year Metelkova Mesto hosts more than 1,500 alternative events in its illegally occupied buildings, catering to a wide spectrum of subcultures, from theatre performances and punk concerts to disability workshops and LGBT club nights. Together with the adjacent museum district, owned by the Slovenian Ministry of Culture – its vast courtyard showcasing the more traditional side of local nightlife, with young couples swing-dancing in the evening sun – the former barracks occupies a special place in the nation’s hearts.

Metelkova is establishing Ljubljana as an area where ideas of all generations can freely flow. Zoran Janković

Artists at work in Metelkova. Photograph: David Levene for the Guardian

“Metelkova is a centre of urban culture,” explains Zoran Janković, the current mayor of Ljubljana who is sympathetic to the squat. “It’s a place for critical reflection, civic engagement – and with its activities it is establishing Ljubljana as an area where ideas of all generations can freely flow.”

A crucial part of this idea, according a German sculptor who regularly visits the site to help out in a gallery, is that Metelkova is for everyone. Old and young, native Slovenes and immigrants from elsewhere in the Balkans, Metelkova is valued by a diverse community as a space to socialise and learn.

This is far removed from the buildings’ original purpose. The military base housing the complex was abandoned shortly after the bloody breakup of the former Yugoslavia – the worst of which Slovenia escaped – just over 24 years ago. The barracks itself was originally commissioned by the Austro-Hungarian Empire in the late 19th century, and during its tumultuous history has been occupied by soldiers from Fascist Italy and Nazi Germany – before becoming a stronghold for the army of the authoritarian Socialist Federal Republic of Yugoslavia.

“The real change happened when Slovenia gained independence in 1991,” explains Janez Premk, a local art historian. “The barracks was abandoned and hundreds of artists and activists petitioned the government to use the site creatively, instead of turning into a commercial building … [That] didn’t work out, so after two years they decided to occupy it themselves and declare it an autonomous zone. The authorities don’t like it, but now they have to tolerate it.”

The entrance to a dub club in Metelkova. Photograph: Ajit Niranjan

The irony of its transformation – from the military arm of a censorious regime to a tolerant artistic community – is what makes the regeneration project of this space so encouraging. But in this regard, Metelkova is not unique. Denmark’s Christiania Freetown is a huge anarchist commune, built on a military base in the centre of Copenhagen and occupied by squatters since the early Seventies.

Fast-forward 30 years and Christiania s celebrated as a hippy’s paradise – in part due to its tolerant ethos and eccentric architecture, and also because of its Green Light District: a street of hash stands where Danish police usually turn a blind eye to a thriving cannabis trade.

But despite the liberal ideals attributed to Christiania, the reality is less than utopian. Over time, the pot-smoking hippies have steadily been replaced by biker gangs; the drugs trade taken over by organised criminal groups exploiting the lack of police presence and the million foreign visitors the Freetown receives each year. The subsequent spates of violence – including shootings and even hand grenades – have put a permanent blight on the commune’s reputation, which cannot be offset by the Bohemian lifestyles of its residents.

The authorities don’t like [Metelkova], but now they have to tolerate it Janez Premk

Hash and marijuana for sale in Christiania’s ‘Pusher Street’. Photograph: Yadid Levy/Alamy

Metelkova, in contrast, has built its image firmly on its artistic and cultural credentials. It’s autonomous, but not anarchistic; liberal, but not lawless. The artists meet for weekly meetings to discuss the upkeep and maintenance of the squat, but have no pretensions about forming a separate state or undermining Ljubljana’s authority. In this light, the two biggest transgressions – illegal occupation of the buildings and the unlicensed sale of alcohol – can be overlooked by the local government, if not forgiven altogether. To some degree this has already happened. The state – both at a local and national level – is still willing to finance many of the cultural projects coming out of Metelkova. And in 2006 the municipality declared Metelkova a national cultural heritage site, which has so far prevented further demolition.

Whether this will remain the case in the future is uncertain. As he repairs the crumbling walls of the Alkatraz Gallery – the site of the former stables – artist Miha Perne explains that opinion is divided over how to proceed. “There are obvious benefits to buying the land and obtaining full legal status from the authorities,” he says. “But it is difficult to achieve this without compromising Metelkova’s character. So people want different things, and we are still always discussing.”

But from the outside, it looks like the squatters might already be getting the best deal. As a squat, Metelkova benefits from paying zero taxes and rents; as a cultural treasure of the city, it remains relatively protected from the grasp of short-sighted property developers. If it can continue this balancing act, it may yet avoid the fate of Christiania.

Follow Guardian Cities on Twitter and Facebook and join the discussion