The pervert who attacked two women with feces on the Upper East Side was captured Friday in a Brooklyn homeless shelter where he had been living, police said.

Cops brought Ekwan Hill, 42, to the Special Victims Unit in East Harlem, where they said he admitted that he was the man seen in a video of one of the attacks.

As he was being led out, he screamed to reporters, “God did it! God did it!’’

In the first attack, Hill flung manure into the face and onto the torso of a 33-year-old woman walking on East 91st Street at 4:50 p.m. on Monday.

About an hour and a half later, he grabbed the waist of a 27-year-old woman on East 74th Street and shoved a similar putrid package down her pants.

He was charged with forcible touching and assault.

NYPD Chief of Detectives Robert Boyce quoted Hill as saying, “Yeah, that’s me,’’ when shown the surveillance video of one of the attacks.

Cops were led to Hill, who has 21 previous arrests, after shelter workers who had seen the video phoned in a tip.

Police Commissioner Bill Bratton praised the victims for their courageous cooperation.

“They’re tough ladies,” Bratton said, adding, “Obviously, the ghastliness of the crime has upset them.”