Briefly, for one wild happy moment at the start of the 1790s, Erasmus Darwin thought he had a chance of becoming Poet Laureate. His verse was evoking nationwide rapture. Yet within a few years he was attacked as a crank, denounced as an atheist and a spy, lampooned by Gillray as an ape, staggering under a basket of "Jacobin flowers". What was so shocking?

Darwin's long poem "The Botanic Garden" (1789) is one of the most extraordinary - some would say bizarre - works in English literature. Arching between two eras, it was a final exuberant flowering of Enlightenment experiment and optimism but also a glittering treasure trove of images and ideas for the coming Romantic generation, plundered by Shelley, Coleridge, Wordsworth. Four thousand lines of rhyming couplets humming above thickets of footnotes, with engravings by Blake, Fuseli and others, it consisted of two parts, "The Economy of Vegetation", and "The Loves of the Plants".

With wit and sly humour it mixed poetry, science and startling radical notions: a sheaf of "Additional Notes" explored everything from meteors to Wedgwood's Portland vase, from clouds and coal to shell-fish and steam-engines. Most disturbing of all to contemporaries was the poem's first hint of a new theory of biological evolution - 50 years before his grandson Charles published Origin of Species .

Erasmus Darwin was a polymathic genius, as idiosyncratic and expansive as his verse (rumour had it that he cut a half-moon in the dining table to fit his girth). He was born in 1731, the seventh child of a squire whose one claim to fame was the discovery of a fossil ichthyosaur in a rectory garden, and studied at Cambridge and Edinburgh, breathing the heady, improving spirit of the Scottish Enlightenment. In 1756, at 25, he settled in Lichfield, where he became famous as a doctor, treating the poor for free. George III asked him to be his personal physician: Darwin declined, preferring his own small court where the only threat was a visit from the rival Lichfield genius, Samuel Johnson.

Like Johnson, he was huge, clumsy and pock-marked, often sarcastic, and talked with a rolling stammer. Yet he was immensely attractive to women. His first wife Mary died young, a victim of illness, drink and opium, leaving three sons. At 49, after a decade in which he had two daughters by the family governess, Darwin fell desperately in love with a dashing married patient, Elizabeth Pole, and when her husband died he married her and moved his whole family (legitimate and illegitimate) to her Derbyshire mansion. She had three children, and they soon had seven more. Darwin liked sex, prescribing it as a cure for hypochondria. He had none of the worries that would plague Victorian England; masturbation was fine. Flagrantly heterosexual himself, he had plenty of homosexual friends and made no adverse comments.

His broad humanity was one reason for his success: although he dished out the opiates, he had a rare warmth, holding sympathetic views on mental illness and even infanticide. But while medicine provided a living, his two great loves were poetry and mechanics, which he enjoyed with different groups of friends. He could be a literary man in the circle round Lichfield's Canon Seward and his talented daughter Anna. And he could let his inventiveness free-wheel among his allies from nearby Birmingham, who called themselves the Lunar Society, since they met monthly near the full moon, so they had light to journey home.

Darwin was an unstoppable inventor: his futuristic designs included a steam car ("a fiery chariot"); a wire-drawn ferry; a horizontal windmill; an artificial bird; a copying machine and a speaking machine. All these he shared with his remarkable friends: the entrepreneur Matthew Boulton and his Scots partner James Watt, of steam-engine fame; Josiah Wedgwood the potter; Joseph Priestley, discoverer of oxygen and fighting radical; and James Keir, pioneer of the chemical industry. Later members of the group included William Withering, Darwin's bitter rival, who introduced digitalis into mainstream medicine, and two wild Rousseauians, Richard Lovell Edgeworth (father of the novelist Maria) and Thomas Day, the author of Sandford and Merton. Their lives were an interwoven web of stories and their interests were kaleidoscopic. One person's passion immediately sparked off the others. Darwin's preoccupation with botany, for example, was probably prompted by Withering's work around 1775 in applying the new Linnaean classification to British plants.

The Swedish botanist Carl Linnaeus had revolutionised plant taxonomy. In his Systema Naturae he divided them into classes by the number of "male genitals", the stamens (monandria, one stamen; diandria, two stamens), and then into orders by their pistils, the female "genitals": the supporting structure, the calyx, became the "nuptial bed". This meant, of course, that some flowers had far more than a single male - and the sexual naming went further, with some structures compared to labia minora and majora, let alone a whole class of flowers named Clitoria. There was no escaping the link between Linnaean botany and sex. His system was as accessible to schoolgirls as to scholars - and since botany was an accepted feminine subject, worried translators like Withering hunted feverishly for inoffensive English terms for the sexy Linnaean language, much to the scoffing of Darwin.

In the mid-1770s, Darwin was increasingly involved with Elizabeth Pole, whom he addressed in a deluge of verse. But if his romantic yearning was unassuaged, at least his botanical desires could be satisfied. In a valley a mile from his house he created his own botanic garden, damming streams and introducing new plants "uniting the Linnaean science with the charm of landscape". He let Anna Seward see the valley when it was finished. She went alone, she remembered, and "seated on a flower-bank... while the sun was gilding the glen", penned 50 rapid lines to the Genius of the Place. Darwin - the Genius - was properly flattered. It was at this point, said Anna, that he declared the Linnaean system to be "unexplored poetic ground", rich in metamorphic possibilities. Ovid had turned people into plants: they would turn plants into men and women; she would write the verse and he the notes, "which must be scientific".

When Anna urged him to write the poem himself, he demurred, fearing his reputation as a doctor would suffer if he were known to write verse. But in private he now began the work that would grow into "The Loves of the Plants". He dashed down a note in his Commonplace Book: "Linnaeus might certainly be translated into English without losing his sexual terms, or other metaphors, & yet avoiding any indecent idea." Darwin sent Seward's verses to the Gentleman's Magazine in her name, but years later - much to her fury - her lines would appear with out acknowledgement as the opening to "The Economy of Vegetation".

His twin poems grew slowly. Before he married Elizabeth in 1780 and moved first to Radburn, then to Derby, Darwin founded the Lichfield Botanical Society and began translating Linnaeus himself. He also took a personal delight in plants. In the gaps of time, morning and night, Darwin took up his pen. He wrote indoors, balancing a cushion on the arm of his chair and resting his writing board on it; he wrote in his summer-house, its windows opening over the river; on the way to see patients, he wrote in his carriage.

Finally, in April 1789, "The Loves of the Plants" was issued by the radical publisher Joseph Johnson. Immediately, Darwin began work on a second edition, and then a third (including new verses on Cannabis, noting with awe that a plant grown in England shot from seed to 14 ft in five months).

Darwin's rhyming couplets may have been old-fashioned but his subject matter was entirely new. His object, he said, was "to enlist Imagination under the banner of Science". Reversing Ovid, he would bring the plants to life in scenes like "little pictures suspended over the chimney of a lady's dressing room, connected only by the slight festoon of ribbons". His speaker is the Goddess of Botany, and the scene is a Midsummer Night's Dream - land of ancient oaks and love-sick violets, glow-worms and horned snails. In this poetic flip-book of images, each flower is dramatised by the action of stamens and pistils in the "nuptial bed" and translated back into botanic terms in the notes. The contrast is felt in each stanza, like that on tremella, a fungus found in nearby Dovedale. The verse swoops into a kind of hectic botanical sublime, as the lonely Tremella faints amid dark crags, lamenting her secret love:

Through her numb'd limbs the chill sensations dart, And the keen ice-bolt trembles at her heart. "I sink, I fall! oh, help me, help!" she cries, Her stiffening tongue the unfinish'd sound denies.

Darwin's prosaic note has far more genuine pathos: "I have frequently observed fungusses of this genus on old rails and on the ground to become a transparent jelly, after they had been frozen in autumnal mornings."

His notes mix his own observations and those of known authorities with comments from historians, the letters of friends, or travel books that tell him, for instance, that the Ostiaks of Russia can mix mushrooms to produce "intoxication for 12 or 16 hours". He marvels at the clever adaptation of plants and animals, bird and fishes, from the swallow to the whale.

Long metaphors allow Darwin to bring the social, as well as the natural world under his microscope. The drifting plumes of the Carline thistle prompt thoughts of Montgolfier's balloon gliding "Bright as a meteor through the azure tides". Gossypia, the cotton plant, lets him describe the ingenious machines of his Derbyshire neighbour, Richard Arkwright. Cassia, the American cashew nut, evokes a fierce appeal against slavery, since the plant's seeds were swept east across the Atlantic just as the slaves were carried on the opposite course:

Conscience must listen to the voice of Guilt: Hear him, ye Senates! Hear this truth sublime, "HE, WHO ALLOWS OPPRESSION, SHARES THE CRIME".

The Lunar group were stout abolitionists, yet they knew that their own neighbourhood was far from innocent. Darwin wrote in appalled tones to Wedgwood: "I have just heard that there are muzzles or gags made at Birmingham for the slaves in our islands. If this be true, and such an instrument could be exhibited by a speaker in the house of commons, it might have great effect."

Darwin believed manufacturers could be forces for good, raising taste, improving conditions, fighting for reform. (He was particularly close to Wedgwood, whose daughter Sukey married Darwin's son Robert - and their son Charles also married a Wedgwood, his cousin Emma.) And he made his heroic view of industry even clearer in "The Economy of Vegetation". In late 1789 he was canvassing details of more inventions, quizzing Boulton about coining machines and badgering Watt about steam. Watt sent a wry note: "I know not how steam-engines come among the plants; I cannot find them in the Systema Naturae, by which I should conclude they are neither plants, animals nor fossils, otherwise they would not have escaped the notice of Linnaeus. However if they belong to your system, no matter about the Swede."

With hindsight, we quarrel with Darwin's vision of a golden industrial dawn, and question the poetic convention of identifying all great achievements with their designer - forgetting the thousands of navvies who slaved on the canals, for example. But his first public was entranced by the vision of British technological brilliance, where Plenty, Art and Commerce ruled the waves.

In the "Economy of Vegetation", whose four Cantos address the spirits of Fire, Earth, Water and Air, Darwin modestly set out to chart the progress from elemental chaos to the modern world. One can understand how young poets such as Wordsworth and Coleridge and chemists such as Humphrey Davy were equally bowled over. The poem explodes into life with a vision of the creation of the universe, presaging the "Big Bang" theory. Milton meets Herschel, at the thrilling command:

"LET THERE BE LIGHT!" Astonish'd Chaos heard the potent word: - Through all his realms the kindly Ether runs, And the mass starts into a million suns; Earths round each sun with quick explosions burst,

And second planets issue from the first; Bend, as they journey with projectile force, In bright ellipses bend their reluctant course; Orbs wheel in orbs, round centres centres roll, And form, self-balanced, one revolving Whole.

The canto on Fire leads to volcanoes and debates on the formation of the earth, but also to electricity, gunpowder and the "Giant-Power" of steam, and prophecies of flying machines. In "Earth" Darwin swerves from geology to clay and Wedgwood's vases, but also to the "Giant-form" of Liberty embodied in the American and French revolutions (views that would soon be held against him). In "Air", Darwin describes photosynthesis, a new discovery, and the meteorology of winds and air pressure. Writing of Priestley's discovery of "pure air", he imagines that this might be used in a diving bell, and looks forward to a time when adventurers will "journey beneath the ocean in large inverted ships or diving balloons".

The insistence on the non-divine, self-regulating economy of the natural world - implied in the title "The Economy of Vegetation" - was even bolder. Genesis is replaced with a pagan version of Creation, redolent of the French philosophes, or the Epicureans, and imbued with sex:

When LOVE DIVINE, with brooding wings unfurl'd Call'd from the rude abyss the living world.

Through reproduction, he controversially suggested, the imprinted patterns of experience were passed on to each new generation, which progressed beyond, in its turn. "Sexual reproduction is the chef d'oeuvre, the masterpiece of nature," he wrote later.

Nobody had so far formulated a theory of the development of life, free from the guiding hand of the Creator. In his next book, Zoonomia, Darwin would pose this directly, diplomatically employing the Deistic term "First Cause". "Would it be too bold to imagine" he asked, "perhaps millions of ages before the commencement of the history of mankind... that all warm-blooded animals have arisen from one living filament, which THE FIRST GREAT CAUSE endowed with animality, with the power of acquiring new parts, attended with new propensities... delivering down those improvements by generation to its posterity, world without end?"

Darwin was bold, but his timing was terrible. The signs were already ominous. In the Burkean backlash against French revolutionary ideas, the science and politics of the Lunar group were being called into question: the slogan "No philosophers" was chalked on Birmingham doors. On July 14, 1791, provoked by a dinner celebrating the fall of the Bastille, riots erupted in Birmingham. The mob's chief target was Joseph Priestley, whose house and laboratory were burnt to the ground: three years later he emigrated to America. Darwin too suffered. The anti-Jacobin "Loves of the Triangles" of 1794 wickedly parodied his poetry, claiming to show that humanity had risen entirely by its own energies from the "Cabbages of the field to our present comparatively intelligent and dignified state of existence". The parody linked Darwin ineradicably with the French Revolution and irreligious views. It was also, alas, very funny.

Soon poetic taste turned against him: "I absolutely nauseate Darwin's poem," wrote Coleridge, and although he still thought him "the first literary character of Europe, and the most original-minded Man", the preface to the Lyrical Ballads in 1798 firmly placed incidents from common life above fancy and "gaudy" language.

"Too old and hardened to fear a little abuse", Darwin wrote on until his death in 1802. My 1825 copy of "The Botanic Garden" is bound in plain covers with Byron's "Don Juan", as if, to an icily respectable public, both poets were too mad, bad and dangerous to know. Since then Darwin's wayward, speculative, almost Nabokovian work has lingered in the stacks - time to blow the dust off, and read him again.

· Jenny Uglow's book The Lunar Men: The Friends Who Made the Future, 1730-1810, is published by Faber. To order a copy at £22 plus p&p call Guardian book service on 0870 066 7979.