Appeal from an order of the Supreme Court (O’Shea, J.), entered October 29, 2008 in Chemung County, which, among other things, dismissed petitioner’s application, in a proceeding pursuant to CPLR article 70, without a hearing.
In 1999, petitioner was convicted in Supreme Court (D’Amico, J.) in Queens County upon his plea of guilty to one count of sodomy in the first degree and one count of attempted robbery in the second degree. The court imposed consecutive sentences of six years and 2 to 4 years, respectively, but did not impose the mandatory period of five years of postrelease supervision (see Penal Law § 70.45 [2]). When petitioner completed his sentence on August 3, 2006, however, the Department of Correctional Services (hereinafter DOCS) administratively imposed such supervision. At the same time, petitioner was committed to a facility of the Office of Mental Health (hereinafter OMH) pursuant to Mental Hygiene Law § 9.27. In March 2007, petitioner violated the conditions of his postrelease supervision and was returned to the custody of DOCS.
On September 23, 2008, DOCS provided OMH and the Attorney General with notice that petitioner may be a detained sex offender who was nearing his anticipated release date (see Mental Hygiene Law § 10.05 [b]). The Attorney General promptly filed a petition for civil management of petitioner pur*922suant to Mental Hygiene Law article 10 and obtained an ex parte order from Supreme Court (O’Shea, J.) in Chemung County staying his release. On October 6, 2008, Supreme Court (Lewis, J.) in Queens County denied the Attorney General’s May 2008 request that petitioner be resentenced with the addition of postrelease supervision and partially granted petitioner’s earlier petition for a writ of habeas corpus after finding that he had been illegally held pursuant to the postrelease supervision imposed by DOCS. However, due to the existing stay in the civil management proceeding, the court did not release petitioner. Petitioner then applied for a writ of habeas corpus in Chemung County. Supreme Court (O’Shea, J.) dismissed his application, and petitioner now appeals.
As respondents concede, our recent holding in Matter of State of New York v Randy M. (57 AD3d 1157 [2008]) is dispositive of the issue of whether a Mental Hygiene Law article 10 proceeding was properly commenced pursuant to Mental Hygiene Law § 10.03 (g) (1). In that case, as here, the person against whom such a proceeding was commenced had been “improperly and unlawfully in the custody of DOCS due to violating terms of a period of postrelease supervision that was not properly imposed” (id. at 1159). Accordingly, we held that “DOCS was not an ‘agency with jurisdiction’ authorized to issue notice under Mental Hygiene Law article 10” (id. at 1159, quoting Mental Hygiene Law § 10.03 [a]). Nor are we persuaded by respondents’ alternate argument that, unlike in Matter of State of New York v Randy M. (supra), this proceeding was properly commenced because petitioner is a “detained sex offender” as defined in Mental Hygiene Law § 10.03 (g) (5) due to his previous commitment to a hospital facility operated by OMH pursuant to Mental Hygiene Law § 9.27. While petitioner had been committed pursuant to that section, it is nonetheless clear that he was in the custody of DOCS when the proceeding was commenced and DOCS was not an agency with jurisdiction as required by Mental Hygiene Law § 10.05 (b) (see People ex rel. David NN. v Hogan, 53 AD3d 841 [2008], Iv denied 11 NY3d 708 [2008] [establishing that the agency must have legal custody over the detained person when notice is given]). As the notice required by that section was not properly issued, Supreme Court should have granted the writ of habeas corpus and ordered petitioner’s immediate release (see Matter of State of New York v Randy M., 57 AD3d at 1160).
Cardona, EJ., Mercure, Malone Jr. and Kavanagh, JJ., concur. Ordered that the order is reversed, on the law, without costs, writ of habeas corpus granted, and the Department of Correctional Services is ordered to immediately release petitioner.