For years the violent gangs of Glasgow have terrorised their small neighbourhoods, brandishing machetes, axes, baseball bats, even croquet mallets in running, alcohol-fuelled battles, which often left rivals mutilated and dead. It gave Scotland's largest city the unwanted reputation as one of the most dangerous in western Europe.

Now the gangs with names such as the Calton Tongs, Parkhead Rebels and the Garthamlock Young Team, are fading away. They are being broken up and dispersed thanks to a full-frontal assault by the police, prosecutors and council officials. Also working with them is a diffident geographer from Oxford University who has deftly converted a computer programme designed for online retailers into a gang-buster's database.

A multimillion-pound campaign by two specialised police units that were set up in 2008 to combat recreational gang violence appears to be working. Strathclyde police has made about 100 gang-related arrests a month, detaining 4,500 young men and women. They have confronted more than 800 gang members using Facebook, Bebo and YouTube to post provocative images bragging about their weapons, and arrested about 100 of these. Some were as young as 11.

In Strathclyde last year, knife carrying fell by 18%. Serious assaults also fell by 9% last year, a figure that has been cut by 42% since 2006.

It is these kinds of results that have caught the UK government's eye, and led David Cameron, in his emergency statement after the recent riots across England, to cite Strathclyde's success in combating gangs as an inspiration for his crackdown on urban crime. Gang members, frontline police officers and youth workers report increasing evidence that the gangs are disappearing, after the police began collaborating with Glasgow city council and local housing agencies. They have been promoting tailor-made diversion and rehabilitation programmes funded by the Scottish government and charities as an alternative to street fighting.

Scott Taylor, 16, a young man convicted of street violence, testifies to the success of the approach that's been taken. It was, he says, a straightforward combination of coercion and reward.

Taylor joined his local gang, the Gyto, or the Garthamlock Young Team, as a 13-year-old, after admiring older youths gathering outside in the evening. His account echoes that of thousands of children in the city: "You're a wee guy. It looks brilliant. You do whatever you want. There was nothing else to do and there was a buzz from it. Chasing people and everybody running about and all that; you're with all your pals."

As a child, Taylor would go into battle with their nearest rivals, from Ruchazie – a gang that included schoolmates he had played football with – using lengths of wood as weapons. Taylor says that his "team" never used "blades", the usual weapon of choice. After being convicted of gang-related disorder, he was given a community service order and offered a chance to get out by taking up a place with Includem, a Glasgow-based voluntary project specialising in youth rehabilitation.

Taylor took the offer up. He has enrolled on a construction course at college and hopes to become a painter and decorator. He says the Garthamlock Young Team has effectively disbanded. "We've all just stopped fighting together because we were all up in court for it," he said. "One is trying to get in the army and the rest have got jobs. It just disappeared: some of the wee guys are saying it but they don't fight or that. It's now quieter; there's just no as much fighting any more."

Taylor will not know this, but one man partly responsible for his new life is Martin Smith, a quietly spoken geographer and Oxford graduate from the Midlands. He joined Strathclyde police in 2007 and was transferred by the chief constable, Stephen House, to the gangs taskforce when it was set up. Smith has adapted a marketing programme commonly used by online retailers such as Amazon into a police database.

Retailers call itRFM, a highly sophisticated way of measuring and scoring the "recency, frequency and monetary" behaviour of their customers. The programme helps them reward those who buy the most.

Smith calls his version RFG, which stands for the "recency, frequency and gravity" of offenders. It targets those who offend the most. In tandem with a common programme for modelling and analysing data, Smith has produced highly detailed spreadsheets setting out the criminal history and intelligence reports of every known gang member in the area.

They are ranked and scored based on their offending rates: Smith has created a chart of the top 150 Glaswegian gang members. He can also generate an up-to-date top 1,500 chart, if needed. Supported by detailed crime maps showing, graphically illustrated hotspots for every crime on the database, these RFG results are shared with Strathclyde's 134 community policing teams each month. They can be overlaid on Smith's own map showing the territorial boundaries for each of Glasgow's 110 gangs.

"These boundaries are real to gang members," said Smith, who also highlighted a link between alcohol and recreational violence. "They're not real to everybody else but the fights and tensions are at the convergence points, the joins between these territories."

His RFG spreadsheets are also shared with Glasgow council's community safety team, a move that unsettled some city officials. At fortnightly meetings, housing officers share information about gang members' misconduct in council flats, their unpaid parking tickets and domestic disturbances. Community wardens collect and share photographs of gang graffiti tags.

The city's housing agencies pass on CCTV images, which are analysed for gang activity. The head of the taskforce, Chief Superintendent Bob Hamilton, said gang members will be confronted and arrested using that information, if necessary. Equally, the taskforce will order repeated use of stop and search against "named individuals" and on specific streets. Offenders on curfew orders may be visited at 3am to ensure they're at home.

Hamilton's officers often discuss arrests with Glasgow's procurator fiscal (prosecutor) before deciding on an operation. The task force goal is clear: prevent the crime and give the gang members, like Taylor, another route out. "We can't arrest ourselves out of the problem," Hamilton said. "Effectively, until 2008, that was what we were doing. It seems perverse that you need to get into bother [trouble with the police] before someone can help you. That doesn't seem right."

Hamilton would visit the gang members' parents, most often their mothers. "It's heads or tails whether they're going to be the victim or the accused, but someone is going to get hurt. It's our job to prevent that happening. I say to the mums: 'It's your choice whether you want to visit him in jail, or be putting flowers on his grave'," he said.

Although, experienced members of the taskforce, set up by House in 2008, are cautious about claiming they have defeated Glasgow's street gangs, they have seen significant changes.

Detective Sergeant Steven Kattenhorn, a veteran of the Scottish crime and drugs enforcement agency, said the strategy is "definitely working". He rarely hears about the Calton Tongs, which featured in one of his unit's most infamous pieces of CCTV footage. It shows a running battle with a man wielding and firing a poorly made crossbow, while another writhes on the ground clutching a stab wound to his chest.

"There was a lot of enforcement activity taking place in their area and as far as our analyst is concerned, they don't feature any more," Kattenhorn said.

But he added: "You can't just write it off to the police's own activities; there are other factors at play. There are improvements in the general area – improvements in housing. There have perhaps been greater opportunities offered to them. We don't have the same degree of activity in that area that we used to have."

Both gangs are in districts benefiting from a multimillion-pound regeneration projects for the Glasgow 2014 Commonwealth games, being staged nearby. This is one reason why the anti-gangs strategy is so significant to the city: during the hard-fought campaign to win the games, the Canadian Broadcasting Company broadcast a documentary on "The feral boys of Glasgow", highlighting the gang violence. The film also focused on Glasgow's poor health record, particularly in the districts where many street gangs operate. Shettleston, where Includem's offices are located, has the worst life expectancy in the UK, at 63.9 years, about 14 years below the UK average.

Three years ago, the Centre for Social Justice thinktank set up by Iain Duncan Smith coined the phrase "Shettleston man" to describe the appalling health outcomes of its citizens. In the district, 50% of men are smokers and have the second-highest smoking mortality rate in the country. Nearby Springburn has the worst. The Scottish TUC has analysed the latest unemployment figures, released last Thursday, and they found that youth unemployment across east and north Glasgow is increasing. In areas historically blighted by street gangs such as Shettleston, Springburn, Maryhill, it has doubled since 2007.

The number of 18 to 24-year-olds jobless for more than six months has tripled in many districts. Yet some Glasgow street gangs have existed for more than 40 years, springing up with the peripheral housing schemes and high-rise estates built in the 1960s. These include the Haghill Powrie or Powery, have been there since the district's council flats were built; Torran Toi, traceable back to the 1960s, and the Tollcross Wee Men, which has seen several generations join and leave.

Backing up this testimony reduced offending, though are statistics from community project Includem and the police-led Scottish violence reduction unit, which runs the Community Initiative to Reduce Violence. Both projects report cuts of 47% in reoffending by the first groups they have redirected back into education or work.

Angela Morgan, Includem's chief executive, said the key is "early intervention and diversion away from what's potentially a lifetime of gang membership".

For many of these teenagers, it can be a difficult transition. "It's very hard for them to realise how terrible things have been in their lives," Morgan said. "So many deaths these young people have had to experience in their lives; multiple crimes and people going to prison.

"They need to realise what has happened, but people can only make choices if they understand that there are choices which can be made, such as 'What do I want in my life? What's stopping me from getting it? Can you and I work together?'"

So far, Morgan adds, none of the young people sent to Includem have ever answered "no" to the last question. That, she says, is a small but encouraging sign that the gangs crackdown is succeeding.