Neil Cohen will serve the term either in prison or a mental hospital. He must also register as a sex offender under Megan's Law.
The 59-year-old could become eligible for release and be placed under intense supervision in several months.
Cohen did not speak during sentencing. But his lawyer told the judge the former assemblyman has been suicidal and has several mental health issues, including chronic depression.
Cohen pleaded guilty in April.
Cohen, who now lives in Paramus, served 17 years in the state Legislature as a Democrat representing Union County. He resigned following his arrest in July 2008.