The nine, all aged under 30, appeared in court Tuesday charged with "indecent conduct and unnatural acts and membership of a criminal organisation". They were arrested in December in the Dakar suburb of Mbao.
"This is the first time that the Senegalese legal system hands down such a harsh sentence against gays," said Issa Diop, one of four defence lawyers representing the men.
Diop said he would appeal the sentence.
Joel Nana, of the International Gay and Lesbian Human Rights Commission, told AFP: "We are in shock. This is the first case that I have heard of where someone is sentenced to eight years in jail for homosexuality."
Homosexual acts are punishable with a maximum sentence of five years in Senegal, where 95 percent of the population is Muslim.
However, the judge in the case raised the sentence to eight years after taking into account their "membership of a criminal organisation". Most of the men belonged to an association set up to fight HIV/AIDS.
A legal source told AFP the men were arrested after police got an anonymous tip-off. "They were arrested while they were in the act and they had pornographic pictures," the source said.
The head of a Senegalese gay rights organisation, who spoke on condition of anonymity for security reasons, called the conviction discriminatory.
"Many gays are already fleeing to neighbouring countries because our living conditions (in Senegal) are getting worse and worse," he said.
Senegalese gay activists say homophobic sentiments have surged in the last year.
In February 2008 a local magazine focusing on celebrity and nightlife published pictures of what it said was a gay marriage. In the ensuing furore, several men seen in the images fled their homes and in some cases the country.
In August, a Belgian and a Senegalese man were sentenced to two-year prison sentences for "unnatural acts".
And after an HIV-AIDS conference in Dakar in December, an Islamic group denounced as "inappropriate" the participation of gays during its proceedings.