MEXICO CITY (Reuters) - Mexico joined a legal challenge to Arizona’s controversial new immigration law on Tuesday, arguing that the measure is unconstitutional and would harm bilateral relations with the United States.

The Arizona law, which takes effect on July 29, makes it a crime to be in the state illegally. It requires state and local police, during lawful contact, to determine the immigration status of any person they suspect is in the country illegally.

It has been challenged in five separate lawsuits filed in federal courts in Arizona by civil rights and religious groups as well as two local police officers. Plaintiffs say the law is unconstitutional and a mandate for racial profiling.

In a legal brief supporting one of the lawsuits, Mexico argued that the measure is unconstitutional and “raises substantial challenges to the bilateral diplomatic relations between Mexico and the U.S.”

More than 20 million Mexican workers, tourists and students were lawfully allowed into the United States throughout 2009, said the brief, and the government is worried Mexicans will be discriminated against because of racial profiling.

“Mexico is gravely concerned that (Arizona’s law) will lead to ... detentions of Mexican citizens without regard to whether they have taken any actions or exhibited any behavior indicating they are guilty of a crime,” the brief said.

U.S. President Barack Obama has also criticized the law and the U.S. Justice Department is reviewing whether or not it will raise its own challenge.

Polls show the state law is backed by a solid majority of American voters, many who fear increasing drug trafficking and human smuggling over the U.S.-Mexico border.