When the philosopher David Hume offered refuge to the persecuted writer Jean-Jacques Rousseau it was apparently a meeting of minds. But the friendship soon soured, casting a shadow over the Age of Reason and calling into doubt Rousseau's sanity and Hume's reputation

David Hume comes down to us as among the greatest of philosophers. He also exemplifies the man of pristine character, saluted in his own age for his uncommon virtue. Hume was immensely proud of his upright reputation; one might say he gloried in his goodness. In 1776, close to death from bowel cancer, he summarised his life in a short, unrevealing essay. He was, he wrote, "a man of mild disposition, of command of temper, of an open, social, and cheerful humour, capable of attachment, but little susceptible of enmity, and of great moderation in all my passions".

His friend, the economist and moral philosopher Adam Smith, agreed, eulogising Hume after his death as the exemplar of as "perfectly wise and virtuous man as perhaps the nature of human frailty will permit". Historians and biographers have gone along with this image - ignoring Smith's caveat ... "as the nature of human frailty will permit" ...

That human frailty had faced its severest test 10 years earlier when Hume offered to succour the radical author Jean-Jacques Rousseau.

The year was 1766 and Rousseau had just cause to fear for his life. For more than three years he had been a refugee, forced to move on several times. His radical tract, The Social Contract, with its famous opening salvo, "Man is born free, but everywhere he is in chains", had been violently condemned. Even more threatening to the French Catholic church was Émile, in which Rousseau advocated denying the clergy a role in the education of the young. An arrest warrant was issued in Paris and his books were publicly burned.

In The Confessions, a literary landmark described as the first modern autobiography, Rousseau spoke of "the cry of unparalleled fury" that went up across Europe. "I was an infidel, an atheist, a lunatic, a madman, a wild beast, a wolf ..."

Fleeing France, he had found safe haven in a remote village in his native Switzerland. But soon the local priest began to whip up hatred against him, charging him with being a heretic. The atmosphere turned ugly. Rousseau was abused in the street. Some believed this lean, dark man whose eyes were full of fire was possessed by the devil.

One night, a drunken mob attacked his house. Rousseau was inside with his mistress, the former scullery maid Thérèse le Vasseur (by whom he had five children that he notoriously abandoned to a foundling hospital), and his beloved dog, Sultan. A shower of stones was thrown at the window. A rock "as big as a head" nearly landed on Rousseau's bed. When a local official finally arrived, he declared, "My God, it's a quarry."

Rousseau had no choice but to uproot once more. So where next? His saviour would be the Scotsman David Hume.

In October 1763, Hume had gone to the French capital as under-secretary to the newly appointed British ambassador, Lord Hertford.

Today, Hume is known above all for his philosophy, but then he was renowned for being an historian. His first philosophical work, The Treatise of Human Nature, had been, if not exactly ignored, then certainly not acclaimed as the sublime work of genius it is. But his epic six-volume History of England, which had appeared between 1754 and 1762, had become a bestseller, and made him financially independent. Turning his back on the previous mode of history writing as a sequence of dates, names and glorifications, Hume brilliantly combined character studies and the detail of events with an analysis of the broad sweep of underlying forces. The tone was thoughtful, civil, temperate. The series would go through more than a hundred editions and still be in use at the end of the 19th century.

Hume still felt, justly, under-appreciated. The "banks of the Thames", he insisted, were "inhabited by barbarians". There was not one Englishman in 50 "who if he heard I had broke my neck tonight would be sorry". Englishmen disliked him, Hume believed, both for what he was not and for what he was: not a Whig, not a Christian, but definitely a Scot. In England, anti-Scottish prejudice was rife. But his homeland too seemed to reject him. The final humiliation came in June 1763, when the Scottish prime minister, the Earl of Bute, appointed another Scottish historian, William Robertson, to be Historiographer Royal for Scotland.

The invitation from Lord Hertford must have seemed irresistible. Hume's friends travelling in France had already told him about his incomparable standing in Parisian society. And the two years he spent in Paris were to be the happiest of his life. He was rapturously embraced there, loaded, in his words, "with civilities". Hume stressed the near-universal judgment on his personality and morals. "What gave me chief pleasure was to find that most of the elogiums bestowed on me, turned on my personal character; my naivety & simplicity of manners, the candour and mildness of my disposition &tc." Indeed, his French admirers gave him the sobriquet Le Bon David, the good David.

Soon in the French capital it became social death not to be acquainted with him. In his Journal, Horace Walpole (on a prolonged visit to Paris) records, "It is incredible the homage they pay him." To a fellow historian Hume wrote: "I can only say that I eat nothing but ambrosia, drink nothing but nectar, breathe nothing but incense, and tread on nothing but flowers. Every man I meet, and still more every lady, would think they were wanting in the most indispensable duty, if they did not make to me a long and elaborate harangue in my praise."

The lavish attention paid by women must have come as a pleasant shock to this obese bachelor in his 50s. James Caulfeild (later Lord Charlemont), who'd once described Hume's face as "broad and fat, his mouth wide, and without any other expression than that of imbecility", observed how in Paris, "no lady's toilette was complete without Hume's attendance".

Hume was glorified both in court circles and in the so-called "Republic of Letters", that unique French Enlightenment territory of salons governed by outstanding women. The salons became the transmission system of the French Enlightenment, creating, focusing and broadcasting radical opinion. The female hosts were the firm regulators of tact and etiquette: they wanted the guests to shine but they could set the tone of the discussions and insist on clarity of language. Their art was the creation and maintenance of civilised conversation.

In the salons, Hume was introduced to the critics, writers, scientists, artists and philosophers who powered the French Enlightenment, the philosophes. They included the "cultural correspondent for Europe", Friedrich Grimm, and the editors of that vast compendium, the Encyclopédie, the pioneering mathematician Jean d'Alembert and the multi-talented Denis Diderot. Diderot had recognised Hume as a fellow Enlightenment spirit - a cosmopolitan. "I flatter myself that I am, like you, citizen of the great city of the world," Diderot wrote to Hume. Hume also became close friends with the passionate atheist Baron d'Holbach, a major financial supporter of and a contributor to the Encyclopédie. All four men would be crucial in Hume's quarrel with Rousseau.

One salon hostess was a vital link in bringing Rousseau and Hume together: the beautiful, clever and moralistic Madame de Boufflers, in whose dazzling salon, with its four huge mirrors, the young Mozart once performed. The intimate tone of the letters between Hume and Mme de Boufflers indicates that he, at least, became infatuated. A spell apart had Hume writing to her: "Alas! Why am I not near you so that I could see you for half an hour a day." She flattered him that she "admired his genius" and that he made her "disgusted with the bulk of the people I have to live with", ending one note, "I love you with all my heart". Sadly, Hume might have misread the silken manners of her court.

When the ambassador, Lord Hertford, was replaced, Hume's sojourn in paradise ended too. Britain beckoned. Mme de Boufflers asked him to assist the persecuted Rousseau in securing asylum in England. How could Le Bon David possibly say no?

Saviour and exile finally met in Paris in December 1765. There had, until then, been only a short epistolatory relationship between them - marked by mutual effusions of love and admiration. Here is Rousseau on Hume: "Your great views, your astonishing impartiality, your genius, would lift you far above the rest of mankind, if you were less attached to them by the goodness of your heart." After their early encounters in the French capital, Hume penned an unreserved panegyric to a clerical friend in Scotland comparing Rousseau to Socrates and, like a starry-eyed lover, seeing beauty in his adored one's blemishes: "I find him mild, and gentle and modest and good humoured ... M. Rousseau is of small stature; and would rather be ugly, had he not the finest physiognomy in the world, I mean, the most expressive countenance. His modesty seems not to be good manners but ignorance of his own excellence."

Several of his philosophe friends tried to shake Hume from his complacency. Grimm, D'Alembert and Diderot all spoke from personal experience, having had a spectacular falling-out with the belligerent Rousseau in the previous decade. In consequence, they had totally severed relations with him. Most chilling was the warning from Baron d'Holbach. It was 9pm on the night before Hume and Rousseau set out for England. Hume had gone for his final farewell. Apologising for puncturing his illusions, the baron counselled Hume that he would soon be sadly disabused. "You don't know your man. I will tell you plainly, you're warming a viper in your bosom."

At first all seemed well. Rousseau, not only a radical thinker but also one of Europe's most popular novelists, was a star in London. His arrival gave the press the opportunity to congratulate readers on this display of British hospitality, tolerance and fair mindedness. How different from the bigoted, autocratic French!

Of course it must have been galling for Hume, hailed in Paris, to be reduced, in the shrewd observation of an intimate Edinburgh friend, William Rouet, Professor of Ecclesiastical and Civil History, to being "the show-er of the lion". The lion stood out in his bizarre Armenian outfit, complete with gown and cap with tassels, and was almost everywhere accompanied by his dog, Sultan. Hume was astounded by the fuss, somewhat meanly putting it down to Rousseau's curiosity value.

He was still insistent on his love for Rousseau - at least when writing to his French friends. He told one, "I have never known a man more amiable and more virtuous than he appears to me; he is mild, gentle, modest, affectionate, disinterested; and above all, endowed with a sensibility of heart in a supreme degree ... for my part, I think I could pass all my life in his company without any danger of our quarrelling ..." Indeed, a source of their concord, Hume thought, was that neither one of them was disputatious. When he repeated the sentiments to D'Holbach, the baron was glad that Hume had "not occasion to repent of the kindness you have shown ... I wish some friends, whom I value very much, had not more reasons to complain of his unfair proceedings, printed imputations, ungratefulness &c."

Hume worked to find somewhere for Rousseau to live and to engage his friends at Court to pursue a royal pension for the refugee. Initially the immigrant was set up in rooms just off the Strand while Hume stayed at his usual lodging house near Leicester Fields (today's Leicester Square), run by two respectable Scots ladies. But Rousseau was not a city lover. London was in the midst of a manic construction boom. Fuelled by the triumphant end to the seven years war, the capital was the richest, fastest growing city on earth. It had become the lodestone for the talented and ambitious, with foreign trade producing new wealth and shaking up the class order. For Rousseau, however, the city was full of "black vapours".

He moved to the bucolic village of Chiswick to lodge with "an honest grocer", James Pullein. Then, in March 1766, the offer of a country house came from an English gentleman, Richard Davenport, an elderly patron of substantial means. Davenport had an empty mansion, Wootton Hall, in a corner of Staffordshire that seemed to guarantee the solitude for which Rousseau yearned.

En route to Wootton, the exile stopped off at Hume's dwelling in London on Wednesday, March 19 1766. It was their last meeting.

Rousseau was already seized with the glimmerings of a plot; he warned his Swiss friends that his letters were being intercepted and his papers in danger. By June, the plot was starkly clear to him in all its ramifications - and at its centre was Hume. On June 23, he rounded on his saviour: "You have badly concealed yourself. I understand you, Sir, and you well know it." And he spelled out the essence of the plot: "You brought me to England, apparently to procure a refuge for me, and in reality to dishonour me. You applied yourself to this noble endeavour with a zeal worthy of your heart and with an art worthy of your talents." Hume was mortified, furious, scared. He appealed to Davenport for support against "the monstrous ingratitude, ferocity, and frenzy of the man".

Hume was right to be afraid. He knew Rousseau was working on The Confessions: he might even have sneaked a look at early pages on the journey across the Channel. Rousseau wielded the most powerful pen in Europe. His romantic novel Héloïse demonstrated that power, leaving readers weeping and sighing. It was a publishing phenomenon: demand was so great that Parisian booksellers rented it out by the hour. Hume saw his own memory put at risk for all time. "You know," he told another old Edinburgh friend, the professor of rhetoric, Hugh Blair, "how dangerous any controversy on a disputable point would be with a man of his talents."

Hume's eyes were on France, in particular, and his reputation as the good David. His first denunciations of Rousseau were made to his friends in Paris; his Concise and Genuine Account of the Dispute between Mr. Hume and Mr. Rousseau would be published there in French, edited by Rousseau's enemies. He studiously avoided communicating with Mme de Boufflers, knowing she would, as she did, urge "generous pity". Hume's descriptions of Rousseau as ferocious, villainous and treacherous ensured joyful coverage in newspapers and discussions in fashionable drawing rooms, clubs and coffee houses. The actor-manager David Garrick wrote to a friend on July 18 that Rousseau had called Hume "noir, black, and a coquin, knave".

In his reply to Rousseau, Hume (unwisely) demanded that Rousseau identify his accuser and supply full details of the plot. To the first, Rousseau's answer was simple and powerful: "That accuser, Sir, is the only man in the world whose testimony I should admit against you: it is yourself." To the second, Rousseau supplied an indictment of 63 lengthy paragraphs containing the incidents on which he relied for evidence of the plot and how Hume had deviously pulled it off. This he mailed to his foe on July 10 1766. The whole document managed to be simultaneously quite mad but resonating with inspired mockery and tragic sentiment. It was also composed with a novelist's instinct for drama. For instance, among the accusations Hume found trickiest to deal with was Rousseau's claim that on the journey to England he heard Hume mutter in his sleep, "Je tiens JJ Rousseau" - I have JJ Rousseau. In the indictment, Rousseau played brilliantly with these "four terrifying words". "Not a night passes but I think I hear, I have you JJ Rousseau ring in my ears, as if he had just pronounced them. Yes, Mr Hume, you have me, I know, but only by those things that are external to me ... You have me by my reputation, and perhaps my security ... Yes, Mr. Hume, you have me by all the ties of this life, but you do not have me by my virtue or my courage."

Hume was aghast: he could not hope to match prose that he described to a French sympathiser as having "many strokes of genius and eloquence". What he did, instead, was laboriously to go through the indictment, incident by incident, desperately scrawling "lye", "lye", "lye", in the margins as he went along. His annotations became the basis of his Concise Account

Among Rousseau's numerous charges were Hume's misreading of a key letter from Rousseau about a royal pension. That error embroiled King George III. The king was just one of the many prominent figures to be sucked into the quarrel: others included Diderot, D'Holbach, Smith, James Boswell, D'Alembert and Grimm. Walpole became a key player. Voltaire piled in too, unable to resist the chance to strike at Rousseau.

Grimm said that a declaration of war between France and Britain would not have made more noise.

In press coverage of what the Monthly Review called the "quarrel between these two celebrated geniuses" support for Hume was far from universal. While Rousseau was denounced for lack of gratitude, the Monthly Review was not alone in advocating "compassion towards an unfortunate man, whose peculiar temper and constitution of mind must, we fear, render him unhappy in every situation". Letter writers, under cover of pseudonyms such as "A Bystander", also took up the cudgels for Rousseau: one recurring theme was the lack of hospitality and respect accorded the exile, which shamed the British nation. There was poetical support in the St James's Chronicle:

Rousseau, be firm! Though malice, like Voltaire,

And superstitious pride, like D'Alembert

Though mad presumption Walpole's form assume,

And base-born treachery appear like Hume,

Yet droop not thou ...

This even-handed treatment was not what Hume had expected, and not the version he gave Mme de Boufflers, writing that there had been "a great deal of raillery on the incident, thrown out in the public papers, but all against that unhappy man". A cartoon depicting Rousseau as a Savage Man, a Yahoo, caught in the woods was more to Hume's taste. He described it to her with relish. "I am represented as a farmer, who caresses him and offers him some oats to eat, which he refuses in a rage; Voltaire and D'Alembert are whipping him up behind; and Horace Walpole making him horns of papier maché. The idea is not altogether absurd."

So, in less than a year, the relationship between Hume and Rousseau had gone from love to mockery by way of fear and loathing.

In hindsight, it seems unlikely that they were ever going to get along, personally or intellectually. Hume was a combination of reason, doubt and scepticism. Rousseau was a creature of feeling, alienation, imagination and certainty. While Hume's outlook was unadventurous and temperate, Rousseau was by instinct rebellious; Hume was an optimist, Rousseau a pessimist; Hume gregarious, Rousseau a loner. Hume was disposed to compromise, Rousseau to confrontation. In style, Rousseau revelled in paradox; Hume revered clarity. Rousseau's language was pyrotechnical and emotional, Hume's straightforward and dispassionate. JYT Greig wrote in his 1931 biography of Hume, "The annals of literature seldom furnish us with two contemporary writers of the first rank, both called philosophers, who cancel one another out with almost mathematical precision."

While they may be described now as thinkers in "the Age of Enlightenment", how far "Enlightenment" covers a common national experience or meaning is a matter of vigorous dispute. A particular reading of French history tends to shape the general idea of "the Enlightenment" as, broadly, the French philosophes' belief that the application of critical reason to received traditions and structures would bring human advancement. The dominating Enlightenment narrative becomes a small and easily identifiable group of brilliant people, a central activity, the Encyclopédie; the sweetness of the salons balanced by the risk of imprisonment, the focus on reason, and the whole enterprise terminating in the guillotine.

But neither Hume nor Rousseau fitted easily into that narrative and its intellectual consensus. Rousseau, in particular, inveighed against so-called "civilisation", taking aim at the Enlightenment's proud boast of progress (that there had been progress in the human condition, and that with the systematic application of rationality and information, improvements could be speeded up). "Nature has made everything in the best way possible; but we want to do better still, and we spoil everything," he wrote. In his emphasis, not just on reason but on feeling, on sensibilité, he would gain a posthumous reputation as the father of the Romantics.

But Hume, too, is a problematic Enlightenment figure. He used reason to demonstrate the limits of reason and he injected his empiricism with a destructive revolutionary force. Taking empiricism to its logical conclusion, he showed how, if we rely on experience, then we can have no complete confidence in the existence of the external world; we can have no confidence in the laws of nature that we take for granted, such as gravity, and we must drastically rethink our notions of induction, necessity and personal identity. Nor could ethics have a rational foundation. Logic was an inappropriate tool for dissecting morality, like taking a carving knife to water. Reason was a slave to the passions.

True, both Rousseau and Hume assailed the Church: it might seem that in this at least they were emblematic spirits of the Enlightenment. But in fact neither did so in a way that would satisfy the wits and cynics in the salons. Rousseau believed in God's existence, professed his love for God, and his faith in God's goodness ("everything is good, coming from God"), as well as his certainty that there was an afterlife and that the soul was immortal, which "all the subtleties of metaphysics will not make me doubt for a moment".

As for Hume, though he had been damned in Scotland for having too little religion, in Paris, where he squirmed at the disdain directed at believers, his burden was that he had too much. True, he had demolished the arguments purporting to prove the existence of God, including the argument from design - the claim that only a supreme and benevolent being could explain the wonder and order in the world. This argument, Hume insisted, was untenable. How could it account for the suffering in the world? How can we infer that there is just one architect of the world, and not a co-operative of two or more?

Hume also wrote that "I would not offend the Godly". Once, dining with Baron d'Holbach, he claimed he had never seen an atheist and questioned whether they really existed. D'Holbach replied that Hume was dining with 17 of them.

For biographers, the Rousseau affair has been a sideshow in the greater scheme of Hume's astounding achievements. But Hume's behaviour is revelatory. His relationship with Rousseau and the falling-out put him under pressure, and that pressure opens up the man. Through a detailed reading of the constant correspondence, we can see that Hume had not wanted to accompany Rousseau to England in the first place - hoping to delegate that task. And, while Hume was telling his French friends of his love for Rousseau, his cousin John Home, the "Scottish Shakespeare", had noticed only 10 days or so after Hume brought his charge to London, his frustration "with the philosopher who allowed himself to be ruled equally by his dog and his mistress".

A letter of Hume's to Hugh Blair exposes what lay masked by the outpourings of love: "[Living in his Staffordshire solitude, Rousseau] will be unhappy in that situation, as he has indeed been always in all situations. He will be entirely without occupation, without company, and almost without amusement of any kind. He has read very little during the course of his life, and has now totally renounced all reading: He has seen very little, and has no manner of curiosity to see or remark; He has reflected, properly speaking, and studied very little; and has not indeed much knowledge: he has only felt, during the whole course of his life; and in this respect, his sensibility rises to a pitch beyond what I have seen any example of: but it still gives him a more acute feeling of pain than of pleasure. He is like a man ... stripped not only of his clothes, but of his skin."

In fact, sensibility apart, all this was false. Rousseau was widely read and never without fulfilling occupations, including music and botany. In the English countryside, he was introduced to the collector and botanist, the Duchess of Portland, and they went on blissful expeditions in the Peak District together. And, of course, Rousseau was working on The Confessions. It was Hume's creative life that was over.

Behind Rousseau's back, Hume conducted an obsessive investigation into Rousseau's finances. He asked various French contacts to make inquiries on his behalf - though concealing from each friend that he had also asked the others. Mme de Boufflers was put out to learn that Hume had set both her and D'Holbach on the same errand. "To what purpose?" were these investigations, she demanded of Hume: "You will not become his denunciator, after having been his protector ..." Yes he would. There's no question of Hume's wanting the information to help Rousseau. He himself makes plain that Rousseau's character was at stake: was he a fraud professing to poverty?

He denigrated Rousseau in a letter to D'Alembert in such foul terms that D'Alembert destroyed the letters and replied, with others, urgently counselling the man of moderation to remain moderate. Rousseau, according to Hume, was exposed as "surely the blackest and most atrocious villain, beyond comparison, that now exists in the world".

But there was no plot by Hume, though Rousseau was not entirely wrong when he accused Hume of being a traitor. A satirical letter purporting to be from the King of Prussia, acidly mocking the beleaguered Swiss, was a central plank in Rousseau's construction of a conspiracy. The letter promised Rousseau sanctuary, holding out a lacerating incentive: "If you want new misfortunes, I am a king and can make you as miserable as you can wish."

In fact, Walpole in Paris was the author, composing the hoax (in French) just before Rousseau arrived to meet Hume. Walpole took it round very appreciative salons. The "King of Prussia" letter even made its way into the London press and to Rousseau's refuge in Staffordshire. The exile was very upset. Hume maintained he was totally ignorant of the spoof. But a little literary detective work reveals that he was present at a dinner where the joke started, and that he probably contributed its most wounding thrust - in one letter Mme de Boufflers, who was appalled by the satire, claimed this was common knowledge in Paris. Hume was at two dinners where Walpole read the letter aloud

Hume's handling of the affair was full of malevolence. His letters were flush with half-truths and lies: such as that Rousseau had called him the blackest of men, that he had proof that Rousseau had plotted for two months to dishonour him, that King George III was "very much prejudiced" against Rousseau - all plainly untrue. And after Rousseau returned to France to live under the protection of Mme de Boufflers, Hume informed Smith that Rousseau was being shunned. He suggested to Mme de Boufflers and others that for his own sake Rousseau would best be locked away as a madman. Le Bon David's reason had become a slave to his passions.

In Paris as tutor to the Duke of Buccleuch on the Grand Tour of Europe in 1766, Adam Smith was among those who advised restraint. When he delivered his posthumous tribute to his friend "as approaching nearly to the idea of a perfectly wise and virtuous man as perhaps the nature of human frailty will permit", Smith had seen at first hand how susceptible to human frailty Hume was after all.

· David Edmonds and John Eidinow are co-authors of Rousseau's Dog: Two Great Thinkers At War In The Age of Enlightenment, published by Faber & Faber, price £15.99