The floodwaters that engulfed the village of Topcic Polje in central Bosnia-Herzegovina have finally retreated, as they have done across thousands of other villages in Bosnia, Serbia and Croatia. Three months of rain fell in three days – the worst floods for 120 years, killing 35 people and causing damage that will cost more than €4bn to repair.

Two weeks ago, the street running through Topcic Polje – a typical agricultural village in central Bosnia, which suffered some of the worst deluges – wound its way beneath metres of water; almost all villagers had to leave their houses and seek shelter elsewhere. Since the rains abated, people have returned to clear and clean their homes, trying to ascertain what is left, what is salvageable, as have a million others across the country and in neighbouring Serbia and Croatia, most of them uninsured and facing a loss of livelihood.

The land they returned to is wrapped in mud, buildings awash. Many have subsided; possessions and farms have been destroyed. Here and there dead animals lie decomposing. But volunteers have arrived from all over the country to bring help and hope, and there is Bosnian defiance too; jokes circulate featuring, as ever, the two favourite characters Mujo and Suljo: "Do you want to buy a house?" the former asks the latter. "What's the mileage?" responds Suljo. "Only one hundred metres."

Many people have been made homeless for a second time in recent history: Bosnia's war between 1992 and 1995 turned 2 million people into refugees – the clearing of territory of the unwanted, by death or deportation, was the war's hallmark.

But among the many pictures taken of the floods' aftermath, one image captures something else – something different – currently happening in Bosnia, something huge. A lady picks her way along the village road with her son. He wears a football shirt bearing the name of the man who is lifting the heart of afflicted Bosnia for the first time, really, since the country was stillborn into a hurricane of violence in 1992. Edin Džeko is the Manchester City striker who will next weekend don the shirt of his country as it takes the field for the first time ever in a World Cup.

It is hard to imagine a stranger twist of timing: a week today, the Bosnian team, half of whom grew up as refugees far-flung by war, play their opening game in the high temple of football – the Maracanã stadium, Rio de Janeiro – against mighty Argentina, the former world champions. While Bosnia's spirit is tested at home against the wrath of water, its small but famously fanatical tribe of journeying supporters will take on a sea of support from Brazil's close neighbours.

Two weeks ago Džeko took a break from World Cup training to play a charity game for flood victims – together with his national team-mates – against 100 children from families stricken by the deluge. Half of the children passing the ball against their idols were wearing kit with Džeko's name on it; and he ran among them, showing off his skills but allowing the odd successful tackle by some scrawny lad, and beaming a honeyed smile.

I published a book two years ago about survivors of the concentration camps in north-west Bosnia and of other atrocities in the war. In it I wrote: "There is no overstating the importance of Edin Džeko in the iconography of scattered, shattered Bosnia." No one illustrated the point clearer or better than Asmir Selimovic, whom I interviewed for the book in St Louis, Missouri, where he lives as a refugee, studying immunology. As a child, Selimovic escaped mass murder in his home town of Vlasenica because his family fled to spend the war in the besieged town of Srebrenica, where, he says "the only way to disconnect was to play football with a ball made of rolled-up duct tape". Selimovic vividly recalls the day in July 1995 when Serbian death squads arrived in Srebrenica to separate men and boys for execution and "my mother had to dress me up as a girl, so we could board a bus". (In the days that followed, 8,000 Bosnian Muslim men and boys were massacred at Srebrenica.) Selimovic said in 2011: "Džeko is a national idol. When Džeko scores, every Bosnian refugee in the world has scored with him. He is our example, he is our hope." Now, with Džeko on fire for club and country, on the threshold of the World Cup, that sentiment is multiplied a thousand-fold.

At the time of its savage break-up in 1991, Yugoslavia was one of football's powerhouses. The national team reached the quarter-finals of the 1990 World Cup in Italy, knocked out by no less than Diego Maradona's Argentina. Red Star Belgrade won the European Cup in 1991, beating Marseille. Then the Yugoslav army, commandeered by Serbia, went to war with separatist Croatia, and the following year Bosnia's carnage began as Bosnian Serbs sought to remove all other ethnicities from terrain they sought to control. The end of the war saw partition of the country into two "entities", the Republika Srprska and the federation of Bosnia and Herzegovina (BiH), with a Bosniak Muslim and Croat majority. Organised sport had imploded into non-existence, but not the people's passion for football.

The new national teams of Serbia, Croatia, Bosnia and other post-Yugoslav nations emerged gradually. Until now, the post-Yugoslav footballing scene has been dominated, like the politics and diplomacy, by Croatia and Serbia – but no longer.

The first appearance by a Bosnian team on the international stage was a match against Iran's national side, in Tehran, in 1993, by a team from FK Sarajevo, playing as "ambassadors" for the new nation while their city was under siege – and winning 3-1. Congratulating the side, Iranian president Akbar Rafsanjani said: "This is your way of fighting. This is the best way to present your young state to the world." Coincidentally, Iran is the team Bosnia meets in its last group-stage game in Brazil, and must probably beat to proceed, later this month.

After recognition by Fifa, the official Bosnia side played its first match against Albania, losing 2-0, a week after the Dayton agreement, which ended the war in November 1995. The team progressed, separated by only one goal from qualification for the Euro 2004 finals in Portugal, came third in their group for the 2006 World Cup qualifiers and second in 2010, in a group won by eventual champions Spain.

Throughout this time, Bosnia has been on the brink of cracking apart along ethnic fault lines. Football reflected this: Bosnian Serbs support Serbia, not the national team, and Bosnian Croats support Croatia. The president of the Republika Srpska, Milorad Dodik, boasted that the only occasion on which he would support the team of the nation of which he is a citizen and public official would be against Turkey.

Bosnian league matches have long been marked by major riots involving Sarajevo's three teams – two of which are supported predominantly by Bosniak Muslims, one by Serbs – and the two teams in the city of Mostar, one Bosniak and one Croat. When Bosniak FK Sarajevo played Croat Široki Brijeg in 2009, a fan was murdered. This season a match between FK Sarajevo and the team from Banja Luka, capital of the Bosnian Serb entity, had to be abandoned after violence.

The official organisation of national football preserved these divisions in ways both petty and toxic. The Bosnian football association was run by political appointees. In 2010, these included a Bosniak minister for police, a Croat general and a party appointee of Dodik; unlike most football association chiefs, they had no connection to the sport whatsoever.

The national team itself, however, tells another story. On the pitch, it remains the only functioning multi-ethnic organism in the 20-year history of the country. There can be no ethnic veto against a pass out of defence from Croat Toni Šunjic to Bosnian Serb midfielder Zvjezdan Misimovic, to superstar striker Džeko, a Bosniak. Again, Srebrenica survivor Asmir Selimovic puts it well: "The pitch is the place where Bosnia really happens. It is the one glimmer of hope to show who we really are. You can't take all that crap on to a soccer field."

"For us," he says, "the team is Bosnia. It's how Bosnia should be, all three peoples together. If the Serbs don't want to support us, or the Croats, that's their problem. But when Misimovic plays for Bosnia, we'll cheer for him as loud as any other player."

Edin Dzeko, left, with Manchester City's Serbian defender Aleksandar Kolarov celebrate after FA Cup final victory in 2011. Photograph: Andrew Yates/AFP/Getty Images

Haris Pašovic is a theatre director in Sarajevo who made his international name producing Waiting for Godot with Susan Sontag during the siege. A football fanatic, he started shooting a documentary about Džeko and Misimovic (for which he unfortunately never secured funding) and got to know his subjects well, having first met them while both were playing in Germany. "Through the way they spoke about each other," he recalls, "with a lot of respect and friendship, one could see that besides loving to play together, they are great friends. That is not a fairytale but the truth – guys from Bosnia who become world-class athletes, impressive people who work and consort very well." Pasovic calls the partnership "very important for Bosnia", making the country "a little bit more noble, cheerful and humane. And this country needs that so much."

In keeping with this spirit, and against the sectarian farce that was their football federation, Bosnia's fans rebelled in 2010, steered by their "ultra" contingent, the BH Fanaticos. They organised demonstrations, boycotted matches and delayed one game in Oslo with flares and fireworks for an hour. Some players joined in, refusing to appear for the national team until the federation reformed (the vacuum thus left gave Edin Džeko his first chance to play for the team). A match was staged at the Olympic stadium in Sarajevo between an all-star refusenik team and veterans of Bosnian football. The Fanaticos' spokesman in the capital, Nizar Smajic, said at the time: "The politicians wanted to impose their interests on our game. We didn't set out to challenge anything political – we just wanted our game back. But politics found us, because politics are everywhere."

For once in Bosnia, the people won. In April 2011, Uefa and Fifa expelled Bosnia from international competitions until its FA was reforged. Bosnia was readmitted after the political appointees were sacked, the federation taken over by a "normalisation committee", which confirmed as national coach a football legend who had starred for Yugoslavia and Paris St Germain: Safet Sušic. One of football's great minds, and a rock in the shifting sands of the Bosnian game, Sušic enticed back the refuseniks, built a team that came within a goal of qualification for the 2012 European championships in Poland/Ukraine, and took Bosnia to this summer's World Cup. One of Sušic's greatest moments for his country was a hat-trick in 1978 against Argentina, whom Bosnia must now face in Group F.

There is usually a modest street party to celebrate any team's qualification for the World Cup, but when Bosnia secured their place after beating Lithuania last October, whooping crowds of 50,000 fans filled the streets of Sarajevo and elsewhere for mass euphoria and fireworks. It marked what one fan, a concentration camp survivor called Edin Kararic now living in Watford, called "the only good thing that's ever happened to Bosnia".

Bosnia has a football sage – imagine a younger Alan Hansen, Gary Lineker and John Motson rolled into one. Muhamed Konjic is the country's leading sports commentator and a reluctant celebrity having been the national team's first captain and now its public, broadcast face. He was known as "Big Mo" at Coventry City, for whom he was player of the year in 2003; he also took the field for Derby County. Konjic comes from the village of Brijesnica near Doboj in northern Bosnia – as does Džeko's family, originally – which was "ethnically cleansed" by the Serbs in 1992. He spent the war in Tuzla in central Bosnia and fought in the Bosnian army of the republic, before joining the Monaco team, alongside Thierry Henry, which knocked Manchester United out of the Champions League in 1998.

Of these troubled times, and their triumphant outcome, Konjic says, poetically: "There is a symbolic similarity between football and planet Earth. You have to go with the orbit, with the current path, and if you don't follow that path you get left behind. Since punishment by Uefa, we've made fantastic progress, because the people who remain love and live football, and carry football in their hearts. So we've been rewarded with this big occasion, by following the orbit. In Bosnia, nothing is certain – but now we have this lovely straight road ahead, and we have to ensure not to take a wrong turn."

Of Sušic, he adds: "As a player, he always found solutions with technical ability, and as coach he is exactly the same. He enjoys and loves players who are similar to him in their game, and have the same ideas. When you look at how Bosnia plays now, it's all so romantic – and football hasn't been like this for years."

The jewel in the crown is Džeko, a jewel given the name Diamant (diamond) by Bosnian Serb commentator Marjan Mijajlovic after a spectacular goal against Belgium in 2009. I remember when Džeko first played and scored for his country, one steaming night in June 2007 in Sarajevo's Kosevo stadium, above which wartime graves climb the hillsides. The goal was a crucial and glorious equaliser against Turkey when the team was 1-2 down, and they went on to win 3-2.

Džeko can remember only too well the heavy guns that fired without relent from the hilltops that surround the stadium. "Drive them to the edge of madness", was Bosnian Serb general Ratko Mladic's order to the gunners. Some 10,000 people were killed in the city alone, of whom 1,200 were children of around Džeko's age.

Džeko was born in 1986 in the Sarajevo suburb of Brijesce, which was occupied by Bosnian Serbs as they mounted their siege of the city. His family home was destroyed along with 35,000 others, and young Edin was obliged to move with his parents and sister to his grandmother's basement on the "free" but besieged side of the lines under Bosnian republican control.

Džeko is sometimes obliged to explain of all this to reporters who know little or nothing of Bosnia's war. "What was it like?" he was asked once. "It was shit," replied Džeko, caught off guard. In his notes for the match programme accompanying his first game for Manchester City, Džeko introduced himself to fans with economy and disarming honesty: "I had a very sad childhood in the middle of a siege," he wrote. "Our house was destroyed so we had to move in with our grandparents in Sarajevo. The whole family – maybe 15 people – were crammed into an apartment of 35 square metres. I was only young and I cried often. Every day you could hear the guns firing." His mother Belma once called her son indoors on a hunch – seconds before a mortar landed on the exact spot where he had been kicking a ball around. On a wall by his bed was a picture of AC Milan's Ukrainian striker Andriy Shevchenko, the childhood idol he would one day surpass. "We lost friends and relatives," continued Džeko in the programme. "The memory does not leave you."

Džeko the superstar discusses what he learned from his origins with young people, whether back home in Bosnia or in the deprived Harpurhey quarter of Manchester. In both places he urges them against despair and conflict, talking to children about opportunity – activities for which he was made Bosnia's first Unicef ambassador. "I try to do something to make a change," he has said. "I go to schools in Bosnia where there is still much to do. Many of the schools are divided; it's like two schools in one. I try to show the children that it's not important what their name is, or whether they are a Muslim, [Orthodox] Christian or Catholic."

By 2003, Džeko was playing for Željeznicar Sarajevo, traditionally the railway workers' team (željeznice means railway). But few among the officials or fans recognised his talent, apart from the team's Czech manager Jiri Plišek. "Džeko had that mental attitude to the game which makes a special player," he recalls. "He needed to apply it, to make up for a lack of tenacity, so I put him in the second team. He was furious, and so were his parents, who came in to see me and protest! But he understood, showed his inner strength. It's my philosophy that everything cannot happen immediately, and there's no rule when a player will reach his peak. But I saw that Džeko was clearly going to get there."

When Plišek eventually returned home to manage the Czech side FK Ústí nad Labem, he was desperate to bring one player with him. When Labem were lukewarm, Plišek said that if the club would not buy Džeko, he would borrow the required €25,000 himself. Labem conceded, and an official at Željeznicar boasted that his club had won the lottery by getting so much money for the young player.

When Džeko was promoted to play for FK Teplice, he was offered Czech citizenship, and with it the likelihood of international competition. But he declined, insisting he was Bosnian. The same happened when he transferred to Wolfsburg in the German Bundelisga for €4m in 2007, turning down an offer to play for the Germans –who can never be discounted as World Cup winners. After Manchester City bought Džeko for £25m, there was no point in even asking him about citizenship: when the club won the FA Cup in 2011, the Premier League in 2012 and again this year, he celebrated draped in the Bosnian flag.

"These boys," says Plišek, "reach a crossroads when they have to choose who they are. And some understand that glory and money are not everything. By choosing Bosnia, Džeko answered the question 'who am I?' and sent a message to his parents, his children and his country. For me, this is how truly great players are made." "Džeko chose Bosnia over the highest mountains in football," says Asmir Selimovic back in St Louis. "For that, he is our fairytale."

"When we look at our great players," Mo Konjic says, "Džeko stands out not just because of his qualities and his world popularity, but because of his journey. When we look at that journey, we see that he spent the war here, he shares the experience of every Bosnian in the war.

"We see him rise through all that and make his global career, to become a great – a Bosnian great, a world great – but he stayed the same boy. Genuine, kind and straightforward – that's the beauty of his greatness."

Bosnia-Herzegovina fans cheer on their team as they play Ivory Coast in St Louis, Missouri, last week. Photograph: Jeff Curry/Getty Images

This has been a strange and eventful year in Bosnia, which had become virtually a protectorate under international authorities, in which attempts to impose a national flag and anthem, collective national identity and republican democracy have failed.

But in early February, Bosnians defied the apathetic response they had almost come to expect of themselves and took to the streets to protest – initially in Tuzla — against job losses resulting from the privatisation of state industries. The demonstrations intensified and spread across the federation, with strong support in Republika Srpska, unleashing rage and violence – the protesters' demands widening to call for social justice and an end to the corruption of politicians at all levels and among all ethnicities.

Popular so-called "plenums" were formed to articulate the demands from the streets; they dissipated, but sank roots into a society otherwise dependent on rotten political structures and what became a colonial class calling itself "the international community". Above all, the protests challenged the idea of a people defined by ethnic division, although leaders in Republika Srpska tried to use the accession of Crimea to Russia and declarations of independence in eastern Ukraine as role models for the ethnic strife they relish.

Then – just as the nation was preparing for the World Cup – came the floods, causing damage to property comparable to the war. The response of the authorities at local, entity and state levels was virtually nonexistent. Public funds previously assigned to flood protection had disappeared, been embezzled. In the vacuum, people organised themselves to help each other, crossing all imaginable differences.

The response of the football team, as it gathered to train and prepare for Brazil, was remarkable. The AS Roma defender Miralem Pjanic went into a pharmacy and bought its entire contents by way of donation. The team toured stricken areas, including devastated Maglaj and played charity matches, Džeko to the fore in calling for international donations and solidarity between "Bosnian and Serbian brothers". On CNN he said: "So many people have lost their lives, lost their homes. They were trying to build something for themselves and their kids over the past 20 years, and they've lost it, just like that … if anyone can help Bosnia and Serbia in any way, it would be amazing."

In the wake of the floods, tweets clog cyberspace with messages of gratitude from across the ethnic spectrum for Džeko's and the team's efforts: "Džeko, you have warmed my heart, we'll support your team." One image shows flags of all the new countries connected into a map of old Yugoslavia, with the caption: "From the waters arose Yugoslavia."

Sveto Losic, a Bosnian Serb citizen of Banja Luka, is a keen supporter of Serbia's national team, which failed to qualify for the World Cup finals. He says: "I'm very happy with the Bosnian team's success. Maybe there are some people who are not so happy about this Bosnian team, but I will support them and I'm pleased they're going to Brazil. It is very interesting to follow them and see how much love and dedication they give for this."

In Bosnia now, even grown-ups collect footballers' picture-cards and stick them into albums as they did as boys (who of course are doing it too. Even Bosnian girls want to be Džeko these days). In the squares of cities and towns, gatherings are organised for the exchange of stickers. Many of these adults will tell you that this is not the kind of thing one would normally do, but in the moment, why not?

Mo Konjic found that when he toured the flood-stricken areas "the first question was not to ask for help, but to inquire what I thought about the team's chances in Brazil. The only complaint I heard was from a man who grumbled about not having electricity, which meant he was unable to keep up with latest news on the team."

Bosnia must eventually return to more normal times, but people are visibly afraid of what lies ahead. Trust in leaders has reached rock bottom; elections are due in October and people wonder who to vote for. There are no new options. They are afraid the same people and parties will remain in power. Unemployment in Bosnia stands at around 40%, youth unemployment at more than 60%.

As a stark reminder of unfinished reckoning, when the flood waters abated last week around Doboj – to where Džeko traces his family roots – electricians seeking to fix the power lines found, shifted by the mudslides, human remains from another mass grave.

Half of the Bosnian team were part of the wartime diaspora, including Stoke City's goalkeeper Asmir Begovic, who lived in Hrasnica, a suburb of Sarajevo, until he was four. Begovic grew up mostly in Germany and Canada, and it was when he returned to Bosnia for the funeral of a grandfather he never knew "that I felt the scars", he now says, "the bad things, the years I had missed. And I made up my mind I would play for Bosnia. That was the moment I knew where I was from.

"Wherever we were living," he says of his team, "we were all raised as Bosnians – Bosnian is the language of our dressing room. It's an intriguing story because we've come from all around the world – I guess what you'd call a golden generation, raised in different environments but with a common country and a common goal." That goal is the World Cup: "Our country has wanted this so much."

A pre-tournament match against Ivory Coast last Friday was staged, by design, in St Louis, Missouri, which boasts the world's biggest Bosnian diaspora community, estimated at some 60,000. Along Morganford Road, once the ghetto, lies the world's most effervescent "Little Bosnia" in exile, a formerly destitute quarter brought to life. On the night of the game the diva of Bosnian Sevdah music, Hanka Paldum, was also in town for a concert.

So this was the gathering of a clan, to watch Džeko and his team play for real, and Asmir Selimovic made sure to get away from an anaesthesiology course in time to be there, driving four hours from Kansas City. Bosnia won 2-1, with both goals scored by Džeko. Volim te Bosno! (Bosnia I love you) chanted the fans, "as blue and yellow smoke quickly engulfed the indoor stadium, and the smell of gunpowder spread everywhere," says Selimovic. "Not something you normally see in the US, especially not at a football stadium."

The winning goal came from a shot by Bosnian Serb Misimovic parried by the Ivory Coast keeper but sent home by Bosniak Džeko. "The team defines us as a country," says Selimovic.

The match was of special poignancy to the Bosnian striker Vedad Ibiševic, who plays for Stuttgart and who, in the qualifiers, scored the goal against Lithuania that took Bosnia through to the finals. This was a homecoming for Ibiševic, who grew up as a refugee in St Louis.

"I was little, but not that little," he said of the war, speaking on the eve of the game to ESPN. Ibisevic is from Vlasenica – like Selimovic, with whom he played in St Louis – and was forced to flee his home town in 1992. "I saw many, many horrible things," he recalled. His father and uncle were killed, his mother's and father's villages razed. He was among the lucky ones who secured a place on a bus to Tuzla in Bosnian republic-controlled territory, made to walk the last of the journey on foot, past corpses strewn along the road. "People from other countries, they don't understand," he continued. "To them, it's just another soccer game and the goal I scored is just a goal. But it's not just a goal. I think the people who know me and know my family members, they have the same feeling: It's not just a goal. It's much more than that. It's the whole story."

Ed Vulliamy is author of The War Is Dead, Long Live the War – Bosnia: The Reckoning, published by Vintage/Random House. Nidžara Ahmetaševic is a journalist with Slobodna Bosna magazine, Sarajevo. Additional research by Victoria-Amina Dautovic