Sean Shaynak, a former teacher at an elite Brooklyn public high school accused of abusing seven of his female students, pleaded guilty on Tuesday to several crimes, the most serious of which was kidnapping. Under the terms of his plea, he will be sentenced to five years in prison.

Mr. Shaynak, 45, was until last year a math, physics and aeronautics teacher at Brooklyn Technical High School. The case against him began when he sent a 16-year-old former student a photo of his genitals via Snapchat, a messaging app, in June 2014. The girl told her parents about the photo, and her father reported it to the Federal Bureau of Investigation. In August of that year, Mr. Shaynak was arrested and charged in State Supreme Court in Brooklyn with disseminating indecent material to a minor and endangering the welfare of a child, among other offenses.

Investigators then began poring over his digital life, and found a cache of lewd text messages sent to students and a video of Mr. Shaynak having sex with a teenager.

The number of girls he was accused of abusing grew from one to seven. At the time they were involved with Mr. Shaynak, the girls were 14 to 18, the authorities said.