The town of Oberndorf should look a lot nicer. Nature offered plenty of blessings. Its 14,000 inhabitants live sheltered in the green and rocky Neckar valley, where the narrow, sparkling river Neckar grooves its way through the Black Forest in one of Germany's most picturesque corners. This is the heart of Baden-Württemberg: tranquil and prosperous, the sunniest and warmest part of Germany. Yet Oberndorf's town centre doesn't include the cobbled square lined with woodcraft shops you'd expect of a German town like this. Instead, the town consists of several industrial complexes wedged into the valley, with housing estates and giant supermarkets climbing up over the surrounding hills.

Oberndorf has things other than aesthetics to be proud of, for its people are good at making machines – sawing machines, drilling machines, machine tools, machine parts, and its speciality: a two-century tradition of weapons-making. Oberndorf's biggest employer is Heckler & Koch, one of the world's leading makers of firearms, whose "precision engineering" has been fired in every corner of the world. Its MP5 submachine gun is used by the US and UK special forces (Osama bin Laden was, as the German press patriotically reported, probably killed with the upgraded MP7A1). Its G36 assault rifle is military issue everywhere from Germany to Egypt to Brazil to Indonesia and was used by the British SAS in the Iraq war. No one knows for sure how many H&K guns are in use, carried by everyone from Hezbollah to the San Francisco police force, but campaigners estimate there may be anywhere between 7m and 20m G3 assault rifles alone. One estimates that H&K guns kill an average of 114 people a day.

Germany is now third on the list of the world's top arms exporters, behind the US and Russia (the UK is at No 5), with approved arms exports worth €2.1bn (£1.73bn) in 2010. Despite its immense success, H&K is going through tough times. Last July, the company announced it was in debt to the tune of €270m (£223m), a year after a downgrade from ratings agency Moody's. On top of that, the company is caught in a lawsuit with two of its former employees over an illegal deal with Mexico, with a state prosecutors' investigation expected to be concluded soon. The company's troubles have drawn more and more attention in Germany, with a new TV documentary uncovering evidence of another possibly illegal transaction with the Mexican government, which apparently paid H&K €1.2m for technical assistance. The German government says it knows nothing of this.

H&K will not comment on these matters specifically, but a spokesman told the Guardian by email: "Legality and conforming to weapons and export guidelines are our economic foundation – without these, no export licence, no commissions. All our employees are aware of that. For everything else: we follow the political directives, we don't make them."

H&K has also become, as the spokesman pointed out, a vital "economic motor" for the Oberndorf community, which has been producing weapons since Friedrich I of Württemberg installed the first armaments factory in a disused Augustine monastery in 1811. Throughout the 19th century, tens of thousands of bayonets and rifles were made and stacked beneath the giant nativity and crucifixion paintings and gold-leaf finishings on the ceiling.

German soldiers with G36 assault rifles. Photograph: Michael Urban/Reuters

Then, seizing the opportunity presented by the foundation of Germany in 1871, two of its employees, brothers Wilhelm and Paul Mauser, set up for themselves. For decades, the Mausers equipped entire armies – the Swedes, the Ottomans – with whole new factories built to complete the biggest commissions. At its industrial peak, the town employed 11,000 workers. By the second world war, Oberndorf had become essential to Adolf Hitler's war plans. The Führer demanded that the town produce 70,000 Mauser rifles a month, and it delivered them with the help of 5,000 forced labourers from across Europe.

"Oberndorf basically is a weapons factory," says Ulrich Pfaff. "They're synonyms." Pfaff is the town's notorious peacenik, born here in 1937. He can remember watching flamethrowers being tested by the Wehrmacht and the caustic artificial fog that was pumped into the valley to hide the factories from allied bombers. After half a century of development work in Africa, Pfaff returned to his hometown in 2001, and "outed himself" as a pacifist on his retirement. He still receives the odd anonymous warning in the post: round here, he explains, sipping tea in his home full of African carvings, pacifists are Nestbeschmutzer – people that foul their own nests.

"We have to be honest, this is work for people here," says Klaus Kirschner, a former Social Democrat MP, trade unionist and Heckler & Koch engineer in the 1970s. "And Oberndorf just happens to have a tradition in weapons."

But Pfaff thinks this is a town of see-no-evil monkeys – he mimes it and laughs. For someone who receives hate mail, he is a startlingly cheery 77-year-old – all wiry frame, cropped white beard and round glasses – with a habit of breaking into laughter on the flimsiest pretexts: the sudden appearance of his wife on a bicycle, for example, or one of his own jokes. Meeting me at the tiny two-platform railway station, he immediately begins the tour: "That's the old Mauser factory there, it got bought by Rheinmetall Defence, now they make guns for warships, Westinger & Altenburger is down there, they only make sports rifles – and up there," – he waves at the crest of a particularly lush pine-forested hill – "is H&K."

There's a reason that Oberndorf's most famous factory is up over a hill, out of sight of the centre, and it has to do with the town's founding myth: after the war, as French troops were supervising the destruction of the Mauser machinery – three engineers, Edmund Heckler, Theodor Koch and Alex Seidel, pinched two milling machines in the dead of night, hid them on a lorry under a pile of scrap, and drove them to a barracks on the top of a nearby hill that had recently been used to house forced labourers. That barracks, recently divested of its old name, the Adolf Hitler Settlement, allegedly became the very spot where Heckler, Koch and Seidel chose to open their factory as soon as it became legal for Germany to make guns again in 1949. Pfaff claims to have worked on an old Mauser milling machine when, like many local teenagers, he did a summer job at H&K in the 1950s.

Since then H&K has made itself integral to Nato's infrastructure. "Europe and Germany are increasingly being drawn into international conflicts. A number of current crisis spots are 'on our doorstep'," the H&K spokesman wrote. "We feel we share responsibility for the safety and the lives of soldiers and police officers of Nato states and Nato allies. We are conscious of this responsibility and act accordingly."

But H&K's guns aren't just used by friendly countries: they're used by everyone. "If you made a map of where there are no Heckler & Koch guns, you'd have two white patches," Jürgen Grässlin sticks up a thumb. "One: the former Warsaw Pact countries – they're all flooded with Kalashnikovs. Two," – the forefinger comes up – "the Antarctic."

Grässlin is a rotund schoolteacher who lives in the city of Freiburg, 40 miles west of Oberndorf. Not a minute of his 19-hour days are wasted. He reads weapons trade publications on the way to work, and spends his evenings at the RüstungsInformationsBüro (Armaments Information Office), a peace organisation he cofounded in 1992. He's here again this evening, surrounded by his overwhelming paper archive, box files and filing cabinets filled with newspaper clippings and official documents reporting virtually all of Germany's arms exports over the past decades. Grässlin says he has to rattle through dozens of emailed requests every night before bed, from journalists, NGOs, even from German MPs ("We're better informed than they are," he claims).

He keeps track of all of Germany's weapons makers, but Heckler & Koch is his particular passion. He has turned himself into its nemesis. For his latest book, Schwarzbuch Waffenhandel – Wie Deutschland am Krieg verdient (Blackbook Weapons Trade – How Germany profits from war), Grässlin came up with a sum to quantify exactly how deadly H&K has become since 1961, the year when the G3 was first licensed to another country (Portugal, which began exporting them to Africa). Given that about 30 million people are thought to have been killed in conflict since then, of which 63 of every 100 deaths were caused by small arms fire (according to the Red Cross), and given that H&K has a global market share of 11%, Grässlin reckons that Oberndorf's guns have killed 2,079,000 people in the past 63 years – an average of 114 people every day.

Anti-weapons campaigner Jürgen Grässlin. Photograph: Ben Knight

The sale of G3 licences – the classic 1950s assault rifle in the H&K arsenal – proved particularly fatal. The German government sold G3 licences to at least 15 countries, mostly in the 1960s, including several countries that used it to carry out wars and internal suppressions, including Portugal, Turkey and Iran. On top of this, the G3 was also sold directly to countries such as Idi Amin's Uganda, cold war-era El Salvador, and apartheid South Africa. Used in the Vietnam war, the Iran-Iraq war, Northern Ireland, and now Syria, it is the second most widely used assault rifle in the world (after the Kalashnikov), with some estimates suggesting that up to 20m are in circulation (well-maintained rifles can be used for decades).

If you ask any German government of the past 60 years why these sales were approved, the answer is always the same: "stability". In practice "stability" means arming both sides of any source of conflict: so Germany has exported weapons to Israel and Egypt, Greece and Turkey, India and Pakistan, Saudia Arabia and Iran. "Stability is the big lie of German arms exports," says Grässlin.

History has shown how easily the policy can backfire on western security interests. The most obvious example might be the sale of the G3 licence to pre-revolution Iran in 1967, which fell into the hands of Ayatollah Khomeini, who promptly used them to carry out executions in spring 1979 and against western-armed Saddam Hussein in the Iran-Iraq war. Meanwhile, Grässlin has seen Pakistani G3s in the hands of Somali militias, while Hezbollah almost certainly got its supply from Iranian factories.

End-use controls (assurances given by the buyer about where the weapons will be used) are virtually impossible to enforce: once licences have been granted, nothing stops proliferation. Grässlin's book includes an anecdote from a former H&K employee, who told him the Saudis would only sign an end-use agreement for one of its machine guns if it was written in English. "He found out later that non-Arabic documents are not valid under Saudi law," he told me. The pattern of proliferation established through licensing the G3 is being repeated today with the deadlier, upgraded G36, which replaced the G3 as the Bundeswehr's standard rifle in the late 90s. Licences to build this one have already been sold to Spain and Saudi Arabia.

This is not just business – it is apparently Germany's new foreign policy. Angela Merkel's government has overseen a massive increase in the country's arms exports. In 2010, she approved arms exports worth a record turnover of €2.1bn – a tenfold increase on 2000. This is all part of what Grässlin calls "the Merkel doctrine" – sending weapons instead of troops. In his book, Grässlin has made a chart of "the top 10 responsible for arms exports", in which the incumbent chancellor beats all her predecessors. "I put Merkel at No 1 because, unlike the Kohl and Schröder governments, she's now prepared to deliver tanks to Saudi Arabia, which was taboo before, and she was quoted as saying [at a political foundation event in 2011] that Germany will in future send fewer soldiers, but more weapons to conflict zones," he said.

Grässlin's school holidays don't sound much fun. They are trips to all the world's conflict zones to find H&K's victims. "I go and hold up five pictures – the Russian Kalashnikov, the German G3, the American M16, the Belgian FN FAL, the Israeli Uzi – and in Somalia, for example, the fingers always point to the Kalashnikov or the G3," he says. "Then you always get a story – what did your mother get killed by, why do you have no legs?"

In April 2010, after 26 years of painstaking research, Grässlin scored his first significant success on H&K ("I'd just had enough," he says) and filed a lawsuit against H&K over what has now been proved to be an illegal sale of 9,500 G36 rifles to Mexico between 2006 and 2009. State prosecutors took several months to respond to the charges, and it was only after a TV documentary later that year and the subsequent media noise that officers raided the company's headquarters on the hill above Oberndorf.

Within weeks, the H&K executive in charge of supervising the legality of deals – a former judge named Peter Beyerle – had resigned (H&K said he had decided on a "different life-plan"). Over the next four years, more revelations emerged about the illegal sale. The German government had approved it on the condition that the weapons weren't used in a certain four states within Mexico where the police were held to be too corrupt and vicious, and which are embroiled in an ongoing conflict with drug mafias and local militias. It turned out that the Mexican defence ministry had never even heard of this condition and had duly delivered half the guns straight to those four states. H&K responded by sacking two employees, claiming that they had acted without management's knowledge, and those two employees subsequently sued H&K for wrongful dismissal. "That was really exciting," says Grässlin. "Watching them all argue with each other in court." This January, the two employees won the case in a labour court – their sacking was indeed unlawful.

Basiji women march with G3s at a Tehran rally in 1988, near the end of the Iran-Iraq war. Photograph: Kaveh Kazemi/Getty Images

Where is all this headed? The situation is certainly tightening for H&K. The firm's appeal against the court's ruling is to be heard in the Baden-Württemberg state court in the summer, but the state prosecutors' report into Grässlin's charges is expected any day.

In the meantime, the veteran activist is already considering a new lawsuit after revelations that Mexico has started to develop its own assault rifle, the FX-05, apparently modelled on the G36. Talking to Grässlin, it's hard to escape the impression that the Mexico case is the can of worms he's been waiting to open for three decades – the crack in the armour of Europe's deadliest company. "I know everything about that deal," he says. "Every detail: who did what when and why." He's also convinced that it's all down to the pressure of that €270m debt.

"Why do you think they started risking these illegal deals?" Grässlin asks, his elbow resting on a pile of Guns & Ammo magazines. "[CEO and main shareholder Andreas] Heeschen would love to sell up – but who's going to buy a company with that much debt and with all these lawsuits hanging over it? You can imagine how much he loves me!" he says. And then he laughs loudly, delighted at the joke.

• The caption of the second picture was amended on 28 February 2014 because the original said the photo showed German soldiers with G3 assault rifles. This has been corrected to say G36 rifles.