Texas Gov. Rick Perry found himself on the defensive in a Republican presidential debate here Monday night, pilloried for suggesting that states should take over Social Security, attacked for trying to mandate vaccinations for young girls and roundly criticized for immigration policies he has supported in his state.

Some of the attacks came from former Massachusetts governor Mitt Romney, who is Perry’s principal rival for the party’s nomination. But in contrast to a candidates debate in California last week, the criticism was just as strong and at times stronger from some of the other contenders.

As with last week’s forum, it’s doubtful that Monday’s two-hour exchange will fundamentally alter the trajectory of the GOP race. But it signaled that, as long as Perry is leading opinion surveys, he is likely to be challenged by his rivals from both the left and the right.

Romney led the charge on Social Security and the economy. But Rep. Michele Bachmann (Minn.), former Utah governor Jon Huntsman Jr., former senator Rick Santorum (Pa.) and at times Rep. Ron Paul (Tex.) tried to derail the campaign of the candidate who has leapt to the top of the polls since his entry last month.

Bachmann appeared especially eager to take Perry down, having had her own campaign damaged by his candidacy. During the two-hour debate, co-hosted by CNN and the Tea Party Express, Bachmann looked to reclaim her standing as the favorite of tea party activists and to prompt doubts about Perry’s bona fides.

Perry stood his ground throughout the evening, whether on Social Security or questions raised about Romney on his job-creation record in Texas. On immigration, he affirmed his opposition to building a fence along the U.S.-Mexican border and his support for providing in-state college tuition for children of illegal immigrants — but the issue threatens to continue to dog him in the race.

Only on his support for vaccinating young girls against cervical cancer did he allow that he would do things differently if he could. But he said he was motivated by the need to save lives. That did not satisfy his rivals.

The debate helped to underscore divisions between the establishment and tea party wings of the party, and the battle for tea party support will continue to be an important subplot of the nomination fight.

On Social Security, Romney and Perry picked up where they left off last week. Romney challenged Perry to to say whether he still stood by what he wrote in his recent book about turning the federal retirement program over to the states.

He accused the Texas governor of scaring senior citizens by calling the program a “Ponzi scheme” and an “absolute failure.” Perry said it was Romney trying to scare people with his criticism.

Perry went to some lengths to soften some of his previous remarks. In his opening words on the topic, he sought to assure those who are receiving Social Security and those who are close to retirement. He promised a “slam-dunk guarantee” that neither group would see its benefits cut. But for younger workers, he said it is essential for the country to face the program’s financial problems.

Romney pressed him. “Do you still believe that Social Security should be ended as a federal program as you did six months ago, when your book came out, and returned to the states or do you want to retreat from that?”

“I think we ought to have a conversation,” Perry interjected.

“We’re having that right now, Governor. We’re running for president,” Romney said.

Perry said that Romney, in his book, had said that the Social Security system’s financing would be criminal if it had been done in the private sector. Romney took issue with that. “You said it’s criminal,” he responded. “What I said was Congress taking money out of the Social Security trust fund is like criminal and that is and it’s wrong.”

The exchange over Social Security went to the heart of one of the important arguments between the two candidates, with Romney trying to make the case that what Perry has said and particularly what he has written could disqualify him in a general election. But it wasn’t clear, given the audience’s reaction, whether Perry is on such shaky ground on the issue.

The two also had a sharp exchange about the economy, as Romney tried to chip away at Perry’s assertion that he has had a far superior record at creating jobs. He said Perry was fortunate to be governing in a state that has no state income tax, a Republican legislature, a right-to-work law, and oil and gas resources.

“I think Governor Perry would agree with me that if you’re dealt four aces, that doesn’t make you necessarily a great poker player,” he said.

“Mitt, you were doing pretty good until you got to talking poker,” Perry responded. “But the fact is the state of Texas has led the nation.”

Former House speaker Newt Gingrich (Ga.) tried to trump them both. He said that while he was speaker, he and the policies of Congress did more for the state economies than anything the governors had done.

“In the four years I was speaker, we created — the American people, not me — created more jobs in Utah than under Governor Huntsman, more jobs in Massachusetts than under Governor Romney and more jobs in Texas than in the 11 years of Governor Perry,” he said.

The most heated exchange came when Bachmann and Santorum took on Perry over his support of a cervical cancer vaccine for 11- and 12-year-old girls.

Perry said that he made a mistake by issuing the executive order, which allowed parents to opt out. “If I had it to do over again, I would have done it differently.”

He said he should have worked with the state legislature. “But what was driving me was, obviously, making a difference about young people’s lives,” he said. “Cervical cancer is a horrible way to die. And I happen to think that what we were trying to do was to clearly send a message that we’re going to give moms and dads the opportunity to make that decision, with parental opt-out.”

Bachmann, who consistently received applause from the tea party crowd, hammered Perry on the issue, saying it was an example of government overreach, and also suggested he was cozy with a pharmaceutical company that had contributed money to his campaign.

“I’m a mom. . . . And to have innocent little 12-year-old girls be forced to have a government injection through an executive order is just flat-out wrong. That should never be done. It’s a violation of a liberty interest,” she said.

Perry, explaining his relationship with the pharmaceutical firm said: “The company was Merck, and it was a $5,000 contribution that I had received from them. I raised about $30 million,” he said. “And if you’re saying that I can be bought for $5,000, I’m offended.”

In a strong retort that won her much applause, Bachmann said: “Well, I’m offended for all the little girls and the parents that didn’t have a choice. That’s what I’m offended for.”

Texas state contribution records show that Merck’s political-action committee has given Perry $29,500 since 2000. Most of that came prior to his 2007 executive order requiring the vaccine against the human papillomavirus, or HPV, the most common sexually transmitted infection.

Perry’s former chief of staff, Mike Toomey, worked for Merck as a Texas lobbyist at the time the executive order was issued.

Last month, Toomey co-founded Make Us Great Again, a pro-Perry super PAC that can collect unlimited donations from corporations and wealthy donors.

Bachmann also zeroed in on Perry and Romney over health care, suggesting that neither is committed to repealing President Obama’s health-care law.

Immigration came late in the debate but also provided sparks, giving Bachmann and Romney a chance to get to the right of Perry, who as governor has allowed the children of illegal immigrants to pay in-state tuition.

Perry defended the program as “the American way,” but some in the audience booed him.

“I’m proud that we are having those individuals be contributing members of our society rather than telling them, ‘You go be on the government dole.’ ”

Romney argued that providing such benefits only gives incentives to people to come to the country illegally, and he said he supports building a fence to secure the border.

Huntsman, who had a strong performance in California, again tried to raise doubts about the two leading GOP candidates. He used the questions on immigration to accuse Romney of flip-flopping, a charge that hurt the former Massachusetts governor in his 2008 presidential campaign.

“I think we can spend all night talking about where Mitt’s been on all the issues of the day. And that would take forever.”

Businessman Herman Cain again stressed that he was the only non-politician on the stage. In response to criticism that he doesn’t know how Washington works, he said, “Yes I do,” he said. “It doesn’t. The American people are ready to do something bold. We need a bold solution to get this economy going.”

Staff writer Dan Eggen also contributed to this story.