Most people think castrating choirboys is inhumane - but not singer Ernesto Tomasini. "I regret not having been castrated," he says. "I would have perfectly happily given up my masculinity for my art." Just over a century ago he would have got his wish: at the height of the craze for male sopranos, 5,000 boys a year were castrated in order to preserve their unbroken voices. Those who proved mediocre mouldered away in parish choirs, but the successful "sacred monsters" were cosseted and adored. The last official castrato, Alessandro Moreschi, retired from the Sistine Chapel in 1913, though some historians suspect that Domenico Mancini, who sang in the papal choir until 1959, was a secret castrato.

Growing up in 1970s Sicily, Tomasini was all too aware of the castrato legacy. At 10, he was kicked out of the choir by the priests of the Santissimo Salvatore for "singing mass as Julie Andrews", while his mother wrung her hands at his coloratura hallelujahs. "She never said, 'Don't mince when you sing,' " he recalls, "but that was what she meant."

In his teens, he would sing when he was home alone. "The neighbours said, 'Oh, you've got such a lovely soprano voice, Mrs Tomasini.' And she said, 'I don't sing.' So then it was 'What do you do when I'm out? You sing like a woman!' "

Tomasini eventually unleashed his four-octave voice on the Italian cabaret circuit, and still performs at the ICA and the Soho revue bar Madame JoJo's as The Techno-Castrato and as The Amazing Tomasini. But he has also started singing the castrato roles that, since Moreschi died in 1922, have been sung by women. The postwar countertenor Alfred Deller inspired Tippett and Britten to write high-pitched male parts, but it is only recently that countertenors - including artists such as Andreas Scholl and David Daniels - have reclaimed castrato roles.

Such performers have proved that it is possible to achieve some of a castrato's range without recourse to surgery, but Tomasini longs for the frenzied glamour of 18th-century opera, in which castrati reigned supreme. Lucy Powell, who wrote True or Falsetto, the show that Tomasini is taking to this year's Edinburgh festival, cannot quite bring herself to agree with him on the benefits of castration. "The difficulty is that you can't make that decision as an adult. I know there are many fetish sites where people are making that decision on a daily basis, but they're not doing it for music."

Eight was the average age for choirboys to be castrated in the 17th century, though officially it was against canon and civil law. Pope Clement VIII admitted castrati into the papal choir in 1599, quoting as justification St Paul's directive: "Let women be silent in the churches." Presumably St Paul would have been satisfied with boys, but Clement VIII had been captivated by the castrati's "angel voices". The Vatican was complicit in recruiting singers not just for the church but, after Pope Innocent XI banned women from appearing on stage in 1686, for opera houses. Last year human rights groups and historians called for a papal apology, but according to Powell, "He was too busy apologising to other people." Tomasini suspects that "many documents have been destroyed".

For poor people, castrating a talented young singer in the family could be a passport to wealth. Still, they shrank from admitting it. Castrated boys often seemed to have met with curious accidents: kicked, bitten, born deformed and (most implausibly) gored by wild boars. Many castrati found it psychologically expedient to believe the euphemisms. One singer, castrated around 1840 after - his parents claimed - a pig attack, once grabbed a knife and said: "If I learnt that it was my father who reduced me, I would kill him with this knife."

The orchidectomies (as they are technically known) were shrouded in secrecy. Only the dodgiest surgeons would attempt them, and they were often a lucrative sideline for village barbers. In the absence of anaesthetic, boys were doped with opium and bathed in milk before having their testicles removed by slitting the groin and severing the spermatic chord. Those who survived were tall, beardless and tended to run to fat. They also had no Adam's apple (the famous 18th-century castrato Farinelli wore a tactical cravat) and their voices did not break. Their larynxes failed to put on the growth spurt that occurs in boys at puberty, meaning that their vocal chords stayed close to the resonating chambers, creating a sound that was sublime, voluptuous and strange.

So otherworldly were these voices that young castrati were hired out, dressed as angels, to keep vigil over the corpses of children. We will never know quite how they sounded - all we have are some 1902 recordings of Moreschi, well past his prime, on single-sided shellac discs. In his inaccurate but sumptuous 1994 film, Farinelli, Il Castrato, Gérard Corbiau suggested the sound by morphing the voices of a countertenor and a soprano.

Created by artifice, the castrati spurned simplicity; instead, they soared, plummeted, scooped and prolonged notes for up to 60 seconds without pausing for breath. Their ability to sing like birds inspired arias full of trills, coloratura and rococo fripperies. Castrati were known for the virtuosita spiccata (where they separated the notes in the trills) and the messa di voce, where they started a note pianissimo, inflated it to a climax and then let it very slowly die away. Farinelli, who liked to duel with a trumpet, competing for agility and breath control, was said to be able to prolong a note for a full minute without taking a new breath, a feat that was showcased in his "portmanteau aria" (all the castrati had them, so-called because they carried them everywhere, inserting them into operas despite their irrelevance).

The castrati's preening extended beyond rewriting the score; Marchesi, an 18th-century castrato with a reputation for bombast, stipulated that he should always enter, whatever the opera, on a hilltop, carrying a sword and a lance, wearing a helmet topped with 6ft-tall red-and-white plumes and beginning with the words, "Where am I?" Their groupies screamed, swooned and tactlessly yelled " Eviva il coltello! " ("Long live the knife!").

In his epistolary novel Humphrey Clinker, Tobias Smollett has Lydia Melford twitter about "a thing from Italy - it looks for all the world like a man, though they say it is not. The voice to be sure is neither man's nor woman's but it is more melodious than either; and it warbled so divinely that while I listened I really thought myself in paradise." When Farinelli sang in London, one woman squealed "One God, one Farinelli", a scene Hogarth lampooned in The Rake's Progress. The charismatic castrato was later summoned by the Queen of Spain to sing her husband, Philip V, out of melancholy. He succeeded, became the most potent politician in Spain, and ran an opera house where he was especially proud of inventing a new way of simulating rain.

Castrati were also supposed to be great lovers: "They could last long," says Tomasini. To Montesquieu they "would have inspired a taste for Gomorrah in people whose taste is the least depraved"; and when Casanova fell in love with a "castrato" who conveniently turned out to be a woman in drag, he asked her to dress as a castrato in bed. For those women who chose, as Dryden put it, to "in soft eunuchs place their bliss/ And shun the scrubbing of a bearded kiss", affairs were idealised and safe. But bedhopping could be risky for the castrati. One was assassinated by his lover's furious family and another, who wrote to the Pope requesting permission to marry on the basis that his castration had been ineffective, received the reply: "Let him be castrated better!"

While the Italians called them "virtuosi", the French sneered at the "cripples" or "capons". Voltaire's character Procurante drawlingly urged Candide to "swoon with pleasure if you wish or if you can at the trills of a eunuch quavering the majestic part of Caesar and Cato". In 1753 the scholar Laurisio Tragiense derided "the insolence of the castrati... who will not tolerate any costumes apart from those in which they hope to appear handsome and dashing". His tone is crushing; he obviously found the castrati anything but. By the 19th century, most people found castration grotesque, leading one virility-obsessed singer with a high voice to splash his posters with the line that he "had the honour to inform the public that he is the father of a family". In 1902 Pope Leo XIII placed a ban on any new castrati joining his choir. Moreschi retired in 1913.

Tomasini and Powell want to look at "the human side of what it meant to be created for art". But they are as interested in the drama as in the trauma. "We'll never get these amazing creatures back again," says Powell. "But I'd like to regain the idea of illusion, that anything is possible on a stage."

· True or Falsetto? is at the Pleasance Cabaret Bar, Edinburgh, until August 26. Box office: 0131-556 6550.