Dharun Ravi, 20, was also placed on three years' probation for his part in an episode that burst onto the front pages after his roommate, Tyler Clementi, threw himself to his death off the George Washington Bridge.
In addition, Ravi was ordered to get counseling and pay $10,000 toward a program to help victims of hate crimes.
"Our society has every right to expect zero tolerance for intolerance," Judge Glenn Berman said in imposing far less than the maximum, 10 years behind bars.
The judge said he would not recommend Ravi be deported to India, where he was born and remains a citizen.
The New Jersey gay rights organization Garden State Equality expressed disappointment with the punishment. In a statement, chairman Steven Goldstein said that while the maximum would have been too much, the 30-day sentence was too close to the other extreme.
"This was not merely a childhood prank gone awry. This was not a crime without bias," Goldstein said.
Prosecutors had asked that Ravi be sent to prison; they did not say how much time he should get, other than that it did not have to be the maximum.
Ravi, his family and his lawyers left the courthouse without comment. He is expected to appeal his conviction, and prosecutors are considering contesting the sentence.
The case began in September 2010 when Ravi's randomly assigned freshman-year roommate asked Ravi to stay away so he and a guest could have privacy. Ravi went to a friend's room and turned on his webcam remotely, and they saw Clementi and his guest kissing. They told others about it through instant messages and tweets.
When Clementi asked for privacy again two days later, Ravi agreed -- then told friends how they could access his webcam. But this time, the webcam was not on when the guest came over. There was testimony both that Clementi unplugged it and that Ravi himself put it to sleep.
The next night, Clementi -- who had learned he was spied on -- committed suicide at age 18.
In imposing sentence, the judge said that while someone might argue the first spying attempt was a foolish prank, "You cannot make or milk that argument a second time."
The judge also berated Ravi for deleting scores of text messages and tweets and trying to influence a witness.
After the suicide, gay-rights and anti-bullying activists held up Clementi as an example of the consequences of bullying young gays. President Barack Obama himself spoke about the tragedy.
Prosecutors offered Ravi a plea bargain that called for no prison time. He turned it down.
After a trial that lasted four weeks, Ravi was convicted of all 15 charges against him, including invasion of privacy, anti-gay intimidation, and trying to cover his tracks by destroying text messages and tweets and tampering with a witness.
Just as Clementi became a symbol for a complicated cause, so has Ravi.
Several hundred supporters rallied at New Jersey's Statehouse last week to denounce the way the state's hate-crime laws were being used on someone they said was not hateful.
They were hoping Ravi would not be sent to prison and that the law could be changed so that someone in his situation again would not be found to have committed a hate crime.