*1158In May 1999, Randy M. (hereinafter respondent) was convicted in Supreme Court (Firetog, J.) in Kings County upon his plea of guilty to one count each of sexual abuse in the first degree and endangering the welfare of a child. The court imposed concurrent sentences of five years and one year in prison, respectively. Because the court did not impose the mandatory period of five years of postrelease supervision (see Penal Law former § 70.45 [2]), the Department of Correctional Services (hereinafter DOCS) imposed such supervision upon respondent’s release from prison on March 20, 2003.1 In August 2007, respondent was reincarcerated for violating the conditions of his supervision.
In July 2008, DOCS provided the Office of Mental Health and the Attorney General with notice that respondent may be a detained sex offender who was nearing his anticipated release date (see Mental Hygiene Law § 10.05 [b]). The Attorney General obtained a securing order from Supreme Court (Michalski, J.) in Erie County to prevent respondent’s release from DOCS’s custody. That same day, Supreme Court (Firetog, J.) in Kings County resentenced respondent to his original sentence plus five years of postrelease supervision, noting that DOCS cannot validly impose any part of a sentence.2
The Attorney General then commenced proceeding No. 1 by filing a sex offender civil management petition (see Mental Hygiene Law § 10.06 [a]), and obtained an ex parte order authorizing DOCS to retain respondent pending a Mental Hygiene Law article 10 probable cause hearing. The next day, respondent commenced proceeding No. 2, pursuant to CPLR article 70, seeking a writ of habeas corpus directing his immediate release from custody. Supreme Court (Zwack, J.) partially granted respondent’s application in proceeding No. 2, determining that DOCS could not retain respondent in its custody on the basis of the violations of postrelease supervision. Rather than ordering his immediate release, however, the court ordered that his release be stayed pending the probable cause hearing (see Mental Hygiene Law § 10.06 [h]). Respondent obtained an adjournment of that hearing and moved to dismiss the civil management proceeding. The court denied that motion. Re*1159spondent appeals from the orders denying his motion to dismiss proceeding No. 1 and denying his release in proceeding No. 2.
Under Mental Hygiene Law § 10.05 (b), “[w]hen it appears to an agency with jurisdiction . . . that a person who may be a detained sex offender is nearing an anticipated release, the agency shall give notice of that fact to the [Attorney [Gjeneral and to the [Commissioner of [Mjental [Hjealth.” An agency with jurisdiction is defined as “that agency which, during the period in question, would be the agency responsible for supervising or releasing such person” (Mental Hygiene Law § 10.03 [a]). As relevant here, a detained sex offender is defined as someone who “is in the care, custody, control, or supervision of an agency with jurisdiction” with respect to a conviction for a sex offense, and is currently serving a sentence for or subject to postrelease supervision for that offense (Mental Hygiene Law § 10.03 [g] [1]).
Because respondent was not lawfully in the custody of an agency with jurisdiction and was not a detained sex offender, he was entitled to dismissal of the civil management proceeding and should immediately be released. It is now clear that DOCS has no authority to impose any portion of a sentence, including mandatory postrelease supervision, and any administratively-imposed aspect of a sentence is a nullity (see Matter of Garner v New York State Dept. of Correctional Servs., 10 NY3d 358, 362 [2008]; Matter of Dreher v Goord, 46 AD3d 1261, 1262 [2007]; see also Matter of Marino v Fischer, 52 AD3d 985, 986 [2008]). As Supreme Court correctly held, and the Attorney General does not contest, respondent could not validly be incarcerated for violating a term of postrelease supervision which was not properly imposed (see People ex rel. Gerard [Colarusso] v Kralik, 44 AD3d 804, 805 [2007]; Matter of Jackson v Cuomo, 20 Misc 3d 1115[A], 2008 NY Slip Op 51356[U], *2 [2008]; People ex rel. Benton v Warden, Adolescent Receiving Detention Ctr., 20 Misc 3d 516, 520 [2008]). The court’s later resentencing of respondent did not operate retroactively to cure the illegal imposition of postrelease supervision, meaning respondent could not validly be punished for violating the terms of postrelease supervision until after it was imposed by a court (see People ex rel. Benton v Warden, Adolescent Receiving Detention Ctr., 20 Misc 3d at 521). Because respondent was improperly and unlawfully in the custody of DOCS due to violating terms of a period of postrelease supervision that was not properly imposed, DOCS was not an “agency with jurisdiction” authorized to issue notice under Mental Hygiene Law article 10 (see Mental Hygiene Law § 10.03 [a]; Matter of State of New York v Robinson, 21 Misc 3d 1120[A], *11602008 NY Slip Op 52111[U], *4 [2008]; compare People ex rel. David NN. v Hogan, 53 AD3d 841, 843-844 [2008], lv denied 11 NY3d 708 [2008]). While DOCS is the agency responsible for releasing respondent, its failure to previously release him from its unlawful custody does not confer upon it the status of an agency with jurisdiction.
Similarly, because respondent was not lawfully in the custody of an agency with jurisdiction and not “currently” subject to a valid term of postrelease supervision when the notice was issued, he did not fall within the definition of a “detained sex offender” (see Mental Hygiene Law § 10.03 [g] [1]; Matter of State of New York v Robinson, 2008 NY Slip Op 52111[U] at *4). As the notice was not properly issued by an agency with jurisdiction concerning a detained sex offender, Supreme Court should have granted respondent’s motion to dismiss the civil management proceeding. Without that proceeding pending, the court also should have granted the writ of habeas corpus in its entirety and ordered that respondent be released immediately.
Cardona, P.J., Carpinello, Lahtinen and Malone Jr., JJ., concur. Ordered that the order entered September 10, 2008 is reversed, on the law, without costs, motion granted and petition dismissed. Ordered that the order entered August 18, 2008 is modified, on the law, without costs, writ of habeas corpus granted in its entirety, and the Department of Correctional Services and Office of Mental Health are ordered to immediately release Randy M.
. Although respondent’s prison sentence did not end until December 6, 2003, he was conditionally released earlier based upon credit earned for good behavior.
. The Attorney General concedes that, after resentencing, respondent’s postrelease supervision would end on March 20, 2008 (see Penal Law § 70.45 [5] [a], [b]). Thus, respondent’s period of postrelease supervision expired before the Attorney General gave notice pursuant to Mental Hygiene Law § 10.05 (h).