A 21-year-old Vineyard man was sentenced to up to four years in state prison on charges of rape of a child.

Trevor J. Medeiros, 21, pleaded guilty Monday to two counts of statutory rape of a child. On the first count, Hon. Tina S. Page, associate justice of the superior court, sentenced him to two and a half to four years at MCI Cedar Junction, a maximum security facility in Walpole.

He was also sentenced to four years of probation on and after the sentence, and ordered to submit a DNA sample, not to contact the victim, not to consume illegal drugs or alcohol, to seek sex offender treatment, register as a sex offender, and not to have unsupervised contact with females under the age of 17. He was also ordered to pay a $90 victim/witness assessment fee and a $65 monthly probation services fee upon release.

Mr. Medeiros was arraigned in August 2012 after police said he had sex with a 13-year-old girl. He was later indicted on the charges.

Mr. Medeiros was in court last week to change his plea from not guilty to guilty, but the proceeding was delayed when Judge Page had concerns about medications Mr. Medeiros was taking at the Dukes County jail. Mr. Medeiros’s defense attorney, Robert Moriarty said Mr. Medeiros was found to be competent by Judge Gary Nickerson on April 10 in Barnstable superior court after a competency hearing and an evaluation.