The night's rituals unfolded slowly. In a small house in a village near the town of Taluqan in northern Afghanistan, a dozen men huddled in a cold, dark room, wrapped in thick blankets and squatting on red cushions. The wind sliced through a plastic sheet nailed to a wooden frame in the mud wall, and a strong aroma of hashish lingered in the air.

A young boy brought a small metal pot, poured warm water on the men's hands and dried them with a small, stinking towel. Dinner was served: plates of meat stew, thick loaves of bread and bowls of yogurt. Then, when the meal was over, one of the guests opened his sash and pulled out four small bottles of Tajik vodka. Solemnly and with half-embarrassed smiles, the men raised their glasses, whispered, "Salamte" and drained them.

As more vodka was drunk, the party grew louder. Its host – a former Taliban commander now in alliance with the Afghan government and Americans – chatted jovially to his guests, mainly local farmers and shopkeepers. Then one of the men produced a sitar and a dancer entered the room.

Dressed in a flowing shirt and long, red skirt, with sherwal pants beneath and small silver bells fastened to hands and feet, the dancer stepped across the floor, face hidden behind a red scarf. The bells chimed with the movement, the skirt brushing past the watching men who stretched out their hands to touch it. The sitar player sang loudly, a love song about betrayal. The dancer twisted and sang hoarsely with him, arms thrown high above a lean, muscular body, moving faster and faster until finally the scarf dropped, revealing a handsome young man's face with traces of a moustache and beard. One of the men quickly grabbed the scarf and started sniffing it.

The practice of taking young boys to perform as dancers at private parties is known as bacha bazi (literally, "boy for play") and is an Afghan tradition with very deep roots. Under Taliban rule, it was banned, but it has crept back and is now widespread, flourishing also in the cities, including the capital, Kabul, and a common feature of weddings, especially in the north. The bacha dancers are often abused children whose families have rejected them. Their "owners" or "masters" can be single or married men, who keep them in a form of sexual slavery, as concubines. The bachas are usually released at the age of 19, when they can get married and reclaim their status as "male", though the stigma of having lived as a bacha is hard to overcome. The Afghan authorities and human rights groups are aware of the plight of bacha boys, but seem powerless to stop it.

In an adjacent room, 16-year-old Mustafa was preparing to dance next. His owner opened a small bundle of clothes and produced a long, blue skirt, crimson shirt, leather straps and bells. Mustafa stood on a table and nervously smoked a cigarette. Holding his thin arms over his head, he allowed two bearded, turbaned men, giggling and laughing, to dress him like a doll. One combed his long hair, and invited the other to have the "honour" of wrapping the straps around his hands and feet.

Later, when he had finished his performance, Mustafa told me his story. "My grandfather kept telling me when I was a child to be careful of men because I was handsome," he said. "One day a mechanic in the town attacked me, my family rejected me and I had to go and stay with that man. Now I am with someone else and he taught me how to dance." He spoke matter-of-factly, then started explaining in great detail about where he buys his women's clothes. How did he feel about the men dressing him? "It's OK," he said.

In Kabul and other Afghan cities, bacha bazi CDs and DVDs are widely on sale from street stalls and carts, serving an audience who can't afford the real thing. In many of the cafes, men sit drinking tea and watching grainy images of boys dancing.

Most of Kabul's musicians congregate in the southern part of the city, an area that was half destroyed by the civil war. In a crumbling hotel, an aged guard opened a gate that led to a dark staircase surrounded by metal grilles. The air was damp and heavy with the smell of hashish, opium, urine and burned oil. On the first floor was a small hall and a few rooms, with shoes and flip-flops piled high outside. On Thursday afternoons, dancing boys and their owners come here to wait for clients to hire them for weddings or parties.

The hotel was crowded with musicians and singers, including 30 Pakistani Pashtun musicians who had come to Kabul to seek refuge from the clampdown in the north-west of their country. One, his hair parted with a ruler in the middle and greased with cream, told me, "The Afghans like us as much as their own musicians. Even Kendeel Kuji [a famous Pakistani singer] is here."

In the same room I met Habib, a dancer, dressed in a spotless white salwar kameez. Two gold rings decorated his manicured fingers. His face was plump and he had a thin, well-groomed moustache above thick, red lips. Why did he start dancing? "I love it. No one forced me to do it – I love it."

When he was 13, he said, his family disowned him, so he went with his lover to Peshawar, fleeing the Taliban. "There I learned how to dance. We could do everything there; I could dress like a woman and dance. Here in Kabul we can't do much: I can only put some red on my lips and dance." He stroked his face with his delicate hands and pushed back his hair with a shake.

After the fall of the Taliban, Habib came back and settled in a small hotel near Kabul. "People accuse us of being homosexuals and transsexuals, but we are not," he said firmly. "We are not trying to be women, we are just dancers. Some men like my dancing and give me tips, but other men like to do other things with me. I have to be careful – they can be dangerous. I know how to manoeuvre to take their money and not let them harm me."

Why did he think other young boys dressed as women and danced? "Because men like women and they are not available, so we act like women. We wink at the rich men in the room, we excite them and they pay us. Two weeks ago, in a town north of Kabul, the elder paid me 4,000 Afghanis [around £49]. But after the programme I had to shout so he would be embarrassed in front of other people, because he wanted to do things with me. Sometimes we get a lot of money. Sometimes we have to spend the night with them and they don't give us anything.

"I am normal, but I like to walk and talk and to perform like a woman. Once, a man offered me $20,000 [£12,250] to become his lover and stop dancing, but I said no because I love to dance. I took only $1,000. Now we are together. Yes, he is married. But he still likes me."