Democratic presidential candidate Beto O'Rourke on Friday said illegal immigrants will not be "criminally prosecuted for being a human being" if he is elected president of the United States.

The former Texas congressman was speaking at a campaign event in Wisconsin when he addressed a question from a reporter about Democratic presidential candidate Julian Castro's criticism of him not supporting the decriminalization of border crossings.

Castro, who was critical of O'Rourke's immigration record at the first Democratic debate, took a shot at two of his Democratic opponents, O'Rourke and Joe Biden, during a presidential candidate town hall hosted by the League of United Latin American Citizens last week, saying they were "wrong" for being against making illegal border crossings a civil violation.

"If we are talking about ensuring that not another child is caged or another family is separated. If we're talking about making sure that no one who seeks asylum or refuge in this country is criminally prosecuted," O'Rourke said. "If we're talking about as president making sure that we treat people with dignity and respect, then we are talking about the same thing. In my administration, we are going to make sure no one is criminally prosecuted for being a human being."

"We are also going to make sure that those who come here to work have a safe, legal option to do that. Those who want to rejoin families, a safe legal option to do that. Dreamers are free forever from any fear of deportation. Ten million or more are working the toughest jobs, come forward, register with the government," O'Rourke continued.

He went on to say there will be no reason for people to cross in between ports of entry, but he said if people do, they will not be criminally prosecuted because they are "seeking safety or shelter or refuge or asylum."

"We will rewrite the immigration code, including 1325 to remove criminal prosecution as a consequence for doing what any human would do. We will reserve criminal prosecution under 1325 for anyone who poses a threat to the safety or security of this country," O'Rourke said.