FILE - In this Jan. 13, 2014 file photo, Arizona Gov. Jan Brewer speaks during her State of the State address at the Arizona Capitol in Phoenix. (AP Photo/Ross D. Franklin, File)

PHOENIX (AP) — Gov. Jan Brewer on Wednesday vetoed a Republican bill that set off a national debate over gay rights, religion and discrimination and subjected Arizona to blistering criticism from major corporations and political leaders from both parties.

Loud cheers erupted outside the Capitol building immediately after Brewer made her announcement.

“My agenda is to sign into law legislation that advances Arizona,” Brewer said at a news conference. “I call them like I seem them despite the tears or the boos from the crowd. After weighing all the arguments, I have vetoed Senate Bill 1062 moments ago.”

The governor said she gave the legislation careful deliberation in talking to her lawyers, citizens and lawmakers on both sides of the debate.

But Brewer said the bill “could divide Arizona in ways we could not even imagine and no one would ever want.” The bill was broadly worded and could result in unintended negative consequences, she added.

The bill backed by Republicans in the Legislature was designed to give added protection from lawsuits to people who assert their religious beliefs in refusing service to gays. But opponents called it an open attack on gays that invited discrimination.

The bill thrust Arizona into the national spotlight last week after both chambers of the state legislature approved it. As the days passed, more and more groups, politicians and average citizens weighed in against Senate Bill 1062. Many took to social media to criticize the bill, calling it an attack on gay and lesbian rights.

Prominent Phoenix business groups said it would be another black eye for the state that saw a national backlash over its 2010 immigration-crackdown law, SB1070, and warned that businesses looking to expand into the state may not do so if bill became law.

Companies such as Apple Inc. and American Airlines and politicians including GOP Sen. John McCain and former Republican presidential nominee were among those who urged Brewer to veto the legislation.

Brewer was under intense pressure to veto the bill, including from three Republicans who had voted for the bill last week. They said in a letter to Brewer that while the intent of their vote “was to create a shield for all citizens’ religious liberties, the bill has been mischaracterized by its opponents as a sword for religious intolerance.”

SB 1062 allows people to claim their religious beliefs as a defense against claims of discrimination. Backers cite a New Mexico Supreme Court decision that allowed a gay couple to sue a photographer who refused to document their wedding, even though the law that allowed that suit doesn’t exist in Arizona.

Leading Republicans in the state had mixed reactions to Brewer’s veto.

House Speaker Andy Tobin, a Republican who voted for the bill, said he respected Brewer’s decision.

“I respect the Governor’s position to veto SB1062, especially in light of the concerns brought up over the past week. I understand the concerns of people of good faith on all sides of this issue,” Tobin said.

But Sen. Al Melvin, a Republican who is running for governor, said he is disappointed by the veto.

“I am sorry to hear that Governor Brewer has vetoed this bill. I’m sure it was a difficult choice for her, but it is a sad day when protecting liberty is considered controversial,” Melvin said in a statement.

Republican Sen. Steve Yarbrough called his proposal a First Amendment issue during a Senate debate.

“This bill is not about allowing discrimination,” Yarbrough said. “This bill is about preventing discrimination against people who are clearly living out their faith.”

Democrats said it was a veiled attempt to legally discriminate against gay people and could allow people to break nearly any law and cite religious freedom as a defense.

“The heart of this bill would allow for discrimination versus gays and lesbians,” said Sen. Steve Gallardo, D-Phoenix. “You can’t argue the fact that bill will invite discrimination. That’s the point of this bill. It is.”

The bill is similar to a proposal last year brought by Yarbrough but vetoed by Brewer, a Republican. That legislation also would have allowed people or religious groups to sue if they believed they might be subject to a government regulation that infringed on their religious rights. Yarbrough stripped that provision from the bill in the hopes Brewer will embrace the new version.

Civil-liberties and secular groups countered that Yarbrough and the Center for Arizona Policy, a powerful social conservative group that backs anti-abortion and conservative Christian legislation in the state and is opposed to gay marriage, had sought to minimize concerns that last year’s bill had far-reaching and hidden implications.

Yarbrough called those worries “unrealistic and unsupported hypotheticals” and said criminal laws will continue to be prosecuted by the courts.

The Center for Arizona Policy argues the law is needed to protect against increasingly activist federal courts and simply clarifies existing state law. “We see a growing hostility toward religion,” said Josh Kredit, legal counsel for the group.

Similar religious-protection legislation has been introduced in Ohio, Mississippi, Idaho, South Dakota, Tennessee and Oklahoma, but Arizona’s plan is the only one that has been passed by a state legislature. The efforts are stalled in Idaho, Ohio and Kansas.

The push in Arizona comes as an increasing number of conservative states grapple with ways to counter the growing legality of gay marriage. Arizona’s voters approved a ban on gay marriage as a state constitutional amendment in 2008. It is one of 29 states with such constitutional prohibitions, according to the National Conference of State Legislatures.

Federal judges have recently struck down those bans in Utah, Oklahoma and Virginia, but those decisions are under appeal.