Washington (CNN) North Carolina's Democratic governor vetoed a controversial bill on Wednesday that would have required sheriffs in the state to closely cooperate with federal immigration enforcement.

Among other things, HB 370, passed by the state House of Representatives on Tuesday and by the state Senate in June, would have required authorities to determine whether prisoners are legal US residents, and if they were unable to do so, to inquire about their residency status with Immigration and Customs Enforcement or the Department of Homeland Security and flag to the agencies if someone was in the country illegally. Authorities also would have been required to allow ICE or DHS officials to interview prisoners upon request and detain prisoners if asked to do so by federal authorities until they could be transferred.

Additionally, the bill mandated that sheriffs would be removed from office if they did not cooperate with the new law, which is being considered amid heightened efforts by the Trump administration to crack down on illegal immigration.

Gov. Roy Cooper said in a statement the bill was "political" and using fear to divide North Carolina.

"This bill, in addition to being unconstitutional, weakens law enforcement in North Carolina by mandating sheriffs to do the job of federal agents, using local resources that could hurt their ability to protect their counties," Cooper said.

Read More