Four days before the end of the Bangladesh war, on Sunday 12 December 1971, a group of Pakistani officers came together in Dhaka's presidential residence. They knew they were about to lose the war they had been fighting for the past nine months to stop East Pakistan from breaking away. Indira Gandhi had intervened on the emergent Bangladesh's behalf, and the Indian army was advancing on the capital. Deciding to hobble the nation whose creation they could no longer prevent, the officers put together the names of 250 people to be arrested and killed: journalists, artists, doctors and university professors. The arrests were made on Monday and Tuesday by marked bands of extreme rightwing collaborators, the razakars. On the Tuesday evening, hours before the official surrender was signed, the victims were taken to the outskirts of the city, where they were executed.

My grandfather, once a prominent political dissident, was in his 70s by then and had already spent almost a decade of his life in Pakistani jails. Upon hearing of the arrests he went into hiding and escaped, but hundreds of other intellectuals were not so lucky. They were shot and dumped in a mass grave in a place called Rayerbazaar, only discovered a few days after independence. Newsreels of the time show the families of the victims standing around a wide ditch, staring in disbelief at the bodies strewn within.

During those nine months in 1971, the world watched while the Pakistani army conducted a campaign of mass murder, rape and ethnic cleansing against an unarmed civilian population. In the name of religious unity, they killed up to 3 million people (although an official Pakistani report only acknowledges 26,000 civilian deaths), displaced another 10 million into neighbouring India, and are alleged to have raped hundreds of thousands of women.

March 26 marks the 40th anniversary of the independence of Bangladesh (that being the day when the war began), and the country has come a long way. Born out of that brutal war of secession with Pakistan, battered by floods, cyclones, coups and political assassinations, it was once a country that had little chance of surviving. But against all odds, Bangladesh has flourished. It no longer fits the cliche of the "basket case" dismissed by Henry Kissinger in 1971.

In 40 years, the economic picture has transformed dramatically. In 1988, Bangladesh relied on international aid for 85% of its annual development budget. That figure is now down to 2%. The economy has grown by 5-6% over the last three years, buoyed by the success of the ready-made garments industry, which is worth more than £7bn, and the remittance sent home by Bangladeshis abroad, estimated last year at $10bn (£6bn). Goldman Sachs recently named Bangladesh as one of its "next 11" emerging economies. Bangladesh has a vibrant women's movement, regular elections, a free press, and a track record of investing in health and education. You only have to visit the capital to get a sense of the pace of change and transformation.

Progress and stability were hard won. The country's first decade saw a series of unstable governments and the murders of its two best-known and beloved politicians: Sheikh Mujibur Rahman, who led the independence movement, and General Zia, a decorated war hero. Their deaths were followed by the nine-year dictatorship of Hossain Mohammad Ershad, appearing to confirm the suspicion that democracy could not flourish in a country with so many problems. But in 1990, a popular movement not unlike the ones we are witnessing in the Middle East today ousted Ershad. There have been four successful parliamentary elections since then.

Soldiers of the Bangladesh Freedom Army march off to war against the Pakistan army, near Jessore, Bangladesh, in April 1971. Photograph: AP

In 2008, the Awami League, led by Sheikh Mujib's daughter Sheikh Hasina Wazed, won a landslide electoral victory. The party campaigned on a platform of secularism and progressive politics, reversing decades of political pandering to far-right groups. Last year, the supreme court restored Bangladesh to its status as a secular republic. Soon thereafter, the high court declared that fatwas were illegal. Harkat-ul-Jihad, the terrorist organisation that had been behind a spate of suicide bombings in 2005, was outlawed. But most importantly, after waiting for four long decades, the victims of the 1971 genocide are finally getting justice. Last year, an international war crimes tribunal was set up, and prosecutors have begun collecting evidence of rapes, killings and arson in preparation for war crimes trials expected to take place later this year. Arrest warrants have been issued against five members of the far-right Islamist party Jamaat-e-Islami, which is accused of siding with the Pakistani army during the war.

Pakistan has never officially apologised to Bangladesh, and the 1974 Delhi treaty has prevented Bangladesh from charging the soldiers and officers responsible for the genocide. But their local collaborators, including the ones who colluded in the killing of intellectuals on 14 December, have thus far been free to remain citizens of Bangladesh, to run for office, and, in some cases, to brag about their past as razakars. With the tribunal, this culture of impunity may finally come to an end. In dealing with the deep wounds of the past, Bangladesh may find a way forward.

If the war crimes tribunal is a sign of the country's ability to move forward, the recent treatment of one of independent Bangladesh's biggest heroes is a symbol of everything that could go wrong with the country.

It would be impossible to celebrate the success of Bangladesh without including the story of Muhammad Yunus, who, 35 years ago, founded a bank on the principle of lending small sums of money to the poor without collateral. That led to the formation of the Grameen Bank, which stands today as one of the most transformative and revolutionary ideas in the modern world. That such an idea should come from Bangladesh is not surprising. When Yunus founded his bank, Bangladesh was far from overturning the cliche of its disaster-prone fate. The very real pressures of poverty are what made his idea possible – it was a home-grown solution to a deep and enduring problem. Microcredit, though it has its critics and could never have been a complete solution to the perils of poverty, has dramatically altered the lives of millions, in Bangladesh and abroad.

Now, the man who brought not only fame but dignity to his country, has been sacked from his job. The reasons appear to be political: Yunus launched a party called Citizens' Power in 2007, and though he disbanded it within months, the political establishment began to see him as a threat. It seems beyond belief that such a man should be vilified by his own government, and his case points to a punishing short sightedness that could threaten much of Bangladesh's current success.

On my last trip to Bangladesh, I visited a company called PHP (Peace, Happiness and Prosperity) in the port city of Chittagong. I was doing research for my next novel, and the company's chairman, a charming, eccentric Sufi named Mizanur Rahman, was my host for the day. He decided to take me on a tour, so we visited his steel rolling mill, his glass factory and his aluminium siding plant. As we drove to one location after another, he sat beside me in his car and gave me advice about my life, my career and my marriage. He often whispered "Alhamdullillah" (Praise Allah), "Inshallah" (God willing) and "Sobhan Allah" (Thanks be to God) between sentences. Hearing I was recently married, he wrote down a prayer in my notebook. "Repeat after me," he said, ignoring my feeble protests. "If you say this prayer, you will have sons."

Later, trying to find ways to reverse what I feared was a hex on my future children, I thought about Rahman's company. Each time we entered one of his factories, he would stand in front of his workers and announce the call to prayer. Once inside, he greeted every man with an embrace, from workers at the rolling mill to the Chinese glassmaker to the south Indian floor manager. His factories were spotless and technologically advanced. His devout religious practice did not seem to have adversely affected the way he ran his business. He was a very rich and important man, yet he had spent all day with me, calling me "daughter", ladling food on to my plate and insisting I take home a bag of oranges from his garden. I learned something important that day, about the way things can sometimes be comingled in Bangladesh – the religious, the civic, the secular, the entrepreneurial. Peace, Happiness and Prosperity.

A few weeks before I was due to leave Dhaka, the stock market suddenly dipped to perilous lows, shaving 25% off its total value within hours. Protesters, some of whom had invested their life's savings, rioted outside the Dhaka stock exchange. The next day, the market bubbled up again and all appeared to be well. The finance minister appeared on television to reassure investors. A few days later, another dip, another riot, another series of announcements. Whether due to fate or manipulation, I could not help but think of it as a symbol of the country itself, a place of great highs and lows, and one in which citizens are asked, on a daily basis, to live on the edge of opportunity.

Tahmima Anam's second novel, The Good Muslim, is published by Canongate in May, £16.99, hardback. She will appear at Southbank Centre's Alchemy festival on 16 April.