PHOENIX — Arizona’s top prosecutor is ready to agree a century-old state law making begging a crime is unconstitutional and cannot be enforced.

Attorney General Tom Horne said Wednesday he will consent to a demand by the American Civil Liberties Union to have a federal judge declare the statute illegal. Horne said some details are still being worked out.

Horne said the ACLU is correct that federal courts have ruled that simply standing around and peacefully asking for money, absent some other illegal act, is protected by the First Amendment right of free speech. And that, he said, makes it unlawful to charge anyone with begging.

The move comes after the city of Flagstaff, which had been using the statute to crack down on panhandlers, agreed earlier this week to change its practices. The agreement Horne said he will sign will extend the reach of that deal statewide, meaning no one can be arrested in the future and charged with violating the law.

Arizona has had some variation of the law, part of the ban on loitering, on the books since territorial days. But it was not challenged until Flagstaff police, responding to complaints by merchants, decided to use the law, adopting a policy of not just citing but actually arresting and booking people who ask for money.

The ACLU got involved after the 2010 arrest of Marlene Baldwin, 77, by an undercover police officer after she approached him and asked for help.

While Baldwin first said she was hungry and wanted some food, she eventually asked for a dollar. At that point the officer arrested her. She has been booked a total of three times for violating the law.

ACLU attorney Dan Pochoda said that violated Baldwin’s rights. So the organization sued, not just to stop the arrests in Flagstaff but to have the entire law voided.

“The statute on its face is unconstitutional,’’ he said. “It allows law enforcement to target and prosecute and jail people for protected speech and expression activities.’’

Horne agreed, saying, “There’s an old Supreme Court case that said you can’t arrest people just for loitering.”

The only thing holding up a final court-approved deal is a dispute over publicizing the change.

“We asked as a matter of convenience for some notification to other state law enforcement agencies so people are aware of and don’t use an unconstitutional provision,” Pochoda said.

“We’re negotiating that,” Horne said.