An undercover MTA police officer was sexually assaulted on a southbound No. 5 train on Wednesday evening when she, and other officers, were on patrol, police said.

Javier Monroy, 39, was arrested after he rubbed up against the officer's left hip and pushed his groin against her, police said. She quickly put out her arm to push Monroy away.

The cops were part of the Transit Manhattan Task Force Anti-Crime Unit and were patrolling on the train.

The officers got off the train at the Union Square station and took Monroy, who is from Gravesend area of Brooklyn, into custody. He was charged with forcible touching and third-degree sexual abuse.

Monroy was held in lieu of a $2,000 bond, according to the Manhattan district attorney's office. His next court appearance is scheduled for October 1.

In a separate incident, a Brooklyn MTA worker was punched by woman just after midnight Tuesday in the Bay Ridge Avenue station. The 52-year-old worker had gotten between the woman and a man she was having a fight with, police said.