Every religion tells a story – as a rule, something to the effect that the structure of our world was ordained long ago by a god or gods, and that we would be well advised to behave in accordance with their desires and designs. But this elemental story is never found on its own; it is always accompanied by a retinue of supplementary anecdotes about what happened next. As the Greek historian Herodotus put it in the fifth century BC, it was not the Gods themselves who 'gave the Greeks their Gods', but Hesiod the mythographer and Homer the poet. Religious traditions are crammed with narratives of revolts, rivalries and derelictions amongst various gods and their devious deputies, not to mention tales of the debatable means by which our intelligence about divine matters was gathered and the tortuous routes by which it found its way to us.

Martin Rowson's cartoon of a sceintist having his eye poked by GodBelievers can elaborate their stories about prophets, augurs, oracles, angels and revelations till they draw their last breath, but they will never be able to eliminate the possibility of a fly in the doctrinal ointment – a muddled or irresponsible messenger, or divine instructions that have been tampered with or misunderstood. There is no rest for the religious – no hiding place from the knowledge that the traditions and rites that make up their religion are human, all too human.

There are honourable traditions of earnest atheism that have sought to defeat religion by attacking its ontological foundations – arguing that there could never be any such thing as a God, and even if there were it would not be entitled to our gratitude or obedience, and that the supposition that we can survive bodily death makes no sense. But these strategies have never been very effective. Religionists are not, on the whole, very interested in fundamental metaphysics. They have never claimed that belief was easy, and many of them have the good sense to admit that when it comes to fundamental theory, they are as liable as anyone else to get things wrong.

But if atheists cannot get very far with direct attacks on religion, they can always fall back on a second strategy: cut the metaphysics, focus on the history, and play on the anxieties that religionists are already prone to. The approach was pioneered by David Hume in an essay on the 'Natural history of religion' which he published in 1757. Hume's scheme was to explain the historical origin and development of the various religions of the world by reference to universal features of human nature: on the one hand, an innate timorousness that has led to the notion of a malicious deity at work behind our every misfortune, and on the other an innate generosity that has fashioned a god who treats us with surpassing sweetness and forbearance in spite of all our faults.

Meanwhile our natural taste for simplicity creates a general tendency for a decline in the number of gods we believe in, and hence the gradual replacement of polytheism with monotheism. Hume assured his readers that he considered the rational foundations of Christianity to be unassailable, but there was little he could do to prevent them from wondering if the historical trend that had left them with only one god in their pantheon would not continue until there were none.

Hume's historical arguments for unbelief lived on in 19th century philosophers like Feuerbach, with his belief in the inevitability of humanism, and anthropologists like EB Tylor, with his notion of 'primitive culture' as a morass of animistic superstition that even the most uncouth races will eventually grow out of. Those approaches have fallen into disrepute, but in the past twenty years the speculative history of religion has been revitalised by an infusion of Darwinism, and outstanding researchers like Jared Diamond, Pascal Boyer, Scot Atran and David Sloan Wilson have started sketching a natural history of religion based in evolutionary biology and based on a time-scale hundreds of times longer than anything envisaged by Hume, Feuerbach or Tylor.

In a new book, the American philosopher Daniel Dennett provides a brilliantly lucid synthesis of these new developments in the natural history of religion. Dennett is already well known as a materialist who holds that there is nothing to consciousness apart from states of the brain, and more recently as a Darwinist who thinks we have still to assimilate the extraordinary implications of 'Darwin's dangerous idea'. In Breaking the Spell he has produced a new assault on religion that, both for its power and for its scrupulousness, deserves to be set alongside Hume's.

Dennett does not propose, any more than Hume did, that human beings have a specific inborn propensity for religious belief; rather, he holds that various mechanisms that have been incorporated into the human brain for good Darwinian reasons (a general 'fiction generating' device, for instance), have produced religious notions as an unintended by-product. He also goes makes good use of Richard Dawkins's controversial notion of memes – hypothetical units of cultural replication whose behaviour is supposed to correspond to that of genes in natural evolution. The survival of a meme-line, like that of a gene-line, will depend on its ability to persuade living organisms to let it be their guest, and religious memes have clearly been remarkably successful in their struggle for cultural survival. But with memes as with genes, evolutionary success is no proof of desirability.

Dennett argues that religions can be as damaging to their cultural hosts as influenza or polio are to their biological ones. In addition they can be peculiarly absurd. It is clear, for example, that the God-meme evolves so rapidly over quite short periods of time that it hardly makes sense to suppose that when today's believers pray to their God they are addressing the same imagined person as their great grandparents were, let alone the mighty prophets of the past. The gentle but impassive force-for-the-good that modern Christians revere, for example, has so little in common with the divine father with a wonder-working son who inspired the Gospels, that even if they existed they would constitute two quite distinct entities – a conclusion which is not only bizarre in itself, but also pretty worrying for those who think that salvation depends on belief in the one true God.

Breaking the Spell is based on lecture courses that Dennett delivered to his students in the United States, and he is clearly a fabulous teacher – patient but punchy, witty but serious, as well as inquisitive, ingenious and frighteningly well-informed. But there are still some things that anger him, and religious fundamentalism is one of them. People of little faith, and people of none, tend to have some admiration for those who appear to be full of it, but according to Dennett this deference is not only illogical but dangerous, because it simply fuels the idiotic fires of extremism. To make matters worse, any secularists who attempt to build bridges with moderate religionists are liable to do more harm than good, since they will only make the radicals feel more embattled in their righteousness, and more intent on fulfilling their own prophecies of death and destruction. The only way to rid the world of religious madness, it seems, is to annihilate religion completely.

If Dennett is appalled by religious fundamentalists and their weak-willed appeasers, he is equally enraged by the obscurantists who, muttering imprecations against scientism, philistinism and reductionism, seek to repulse the incursions of science into the field of meaning, value and culture, and even to defend the vestiges of religious reverence. These fuzzy humanists have, according to Dennett, sold out on scientific objectivity and given way to an absurd and spineless relativism.

No doubt the humanists who cower before the advances of science ought to be careful of the company they keep; but those atheists who join Dennett in fulminating against the horrors of relativism need to be wary too: on this issue, after all, they are on the same side as religious absolutists like the Pope and Osama bin Laden. Of all the predators lurking in the modern intellectual jungle, relativism is surely one of the least dangerous. And those of us who do not believe in any religion would do well to avoid taking our atheism to puritanical extremes: we need to remind ourselves that most of what we prize in human culture has been handed down to us by religious believers, and that we may never succeed in filleting out all the bits that are not to our naturalistic taste.

Our problem is not just about the continuing validity of religious works of art, music and literature, or the vast tracts of the natural sciences that were built on theistic assumptions about the regularity and uniformity of God's creation and the absolute universality of its laws. There are also everyday practical issues where the only guidance we are likely to find comes from notions that have more than a whiff of religiosity about them – issues not so much of accuracy as of grace, or of what you might call moral poetry as opposed to moral accountancy.

For example we may find ourselves pondering the ethics of mourning – how long should we dwell on the death of someone we loved, and how much ought we to want to be unhappy? Or the ethics of reverence: ought we to curb an impulse to piss on gravestones, or shout in churches, or violate a corpse, even if we can sure that no one will be harmed in any way? Or love: can it be motivated by selfishness, and can you be under an obligation to love people you do not particularly like?

When it comes to questions like this I cannot think of anywhere better to look than the Hebrew Bible or the Christian New Testament, or the elliptical works of religious writers like Pascal, Kierkegaard, or CS Lewis; and if that makes me a cherry-picking relativist, so much the better for relativism. On this matter I would rather follow Hume than Dennett: for if Hume was relatively gentle with religious believers, it was not just because he wanted to cover his atheistical tracks, but because he was aware of the danger of throwing out the baby with the bathwater.

Daniel Dennett's Breaking the Spell: Religion as a natural phenomenon  is published by Penguin.