Texas Gov. Rick Perry and former Massachusetts governor Mitt Romney tangled over Social Security, health care and other issues here Thursday in a debate in which the Republican presidential candidates sharply criticized the policies of President Obama and joined in an assault on the federal government.

Romney pressed Perry to explain whether he would dismantle Social Security as a federal program and turn it over to the states, as he has suggested. Perry countered that he would preserve the program for those on it or near retirement and fix it for younger workers. He said he would support a limited role for states to manage retirement security for state employees.

Romney then charged that Perry was running away from what he wrote in his recent book and has said several times in the past months. “There’s a Rick Perry out there that is saying . . . that it’s unconstitutional . . . and it should be returned to the states,” Romney said. “So you better find that Rick Perry and get him to stop saying that.”

The attacks by Romney underscored the intense competition between him and Perry as the leaders in the GOP race. But the other candidates joined in the attacks, signaling their desire to blunt the Texas governor’s early momentum and followed a pattern from two debates earlier this month.

Time and again, Perry found himself on the defensive throughout the nearly two-hour exchange. As in last week’s forum in Tampa, he was criticized for advocating the mandatory vaccination of young girls against a sexually transmitted virus — a position he has said was a mistake but one made with good intentions.

If Perry appeared to give some ground on Social Security, he held firm on his immigration positions. He said he opposes trying to build a fence along the entire U.S.-Mexican border and defended his support for giving children of illegal immigrants in-state college tuition.

Romney said that policy amounted to a nearly $100,000 discount over four years for those students and said it made “no sense.” Former senator Rick Santorum (Pa.) blasted Perry on border protection and the tuition program. Calling him “soft” on immigration, Santorum said: “I think he’s very weak on this issue of American sovereignty and protecting our borders and not being a magnet for illegal immigration.”

Perry said the tuition policy had won the Texas legislature’s backing with only four dissenting votes. “I greatly support it,” he said. He added, “If you say that we should not educate children who have come into our state for no other reason than they’ve been brought there by no fault of their own, I don’t think you have a heart.”

Thursday’s debate was a freewheeling event in which virtually all the candidates played more visible roles than in the previous two debates, which often became a face-off between Romney and Perry. The forum did not settle some outstanding questions about the two front-runners and may have only a limited effect on the overall shape of the contest. The other candidates demonstrated their determination not to be pushed aside.

Fox News, Google and the Republican Party of Florida were hosts of the debate. Many of the questions were solicited from citizens nationwide, adding a different flavor to this forum and sometimes lessening the opportunities for the two leading candidates to go after each other.

The debate featured nine Republican candidates. In addition to Perry, Romney and Santorum, they were: Rep. Michele Bachmann (Minn.), Rep. Ron Paul (Tex.), former House speaker Newt Gingrich (Ga.), businessman Herman Cain, former Utah governor Jon Huntsman Jr. and former New Mexico governor Gary Johnson.

Rep. Thaddeus McCotter (Mich.), meanwhile, announced that he was ending his campaign for the nomination and endorsed Romney.

Obama came under fire repeatedly and the candidates vied to attack what they described as a government that has grown too large and intrusive. The clearest example came during a discussion of education policy in which the Republicans had harsh words for Washington’s role in education.

“You need to dramatically shrink the federal Department of Education, get rid of virtually all of its regulations,” Gingrich said.

There were moments of humor throughout the debate. The most memorable may have been when Johnson, criticizing Obama’s policies, said, “My next-door neighbor’s two dogs have created more shovel-ready jobs than this current administration.”

The debate was one of a series of activities that have drawn several thousand Republican activists to Orlando this weekend. The events include two other candidate forums held by conservative organizations and a Republican Party of Florida straw poll on Saturday. Perry is heavily favored to win the poll. Romney will not participate in that test. He also skipped the Iowa straw poll in August.

Perry and his advisers had signaled before the debate that he was determined to take the fight to his opponents, rather than become a piñata, as he said had been the case in previous debates. He criticized Romney for changing his positions on issues and near the end of the debate, the two had perhaps their sharpest exchange yet — although Perry had some difficulty delivering his lines.

“I think Americans just don’t know sometimes which Mitt Romney they’re dealing with,” he said. “Is it the Mitt Romney that was on the side of against the Second Amendment before he was for the Second Amendment? Was it before he was before the social programs, from the standpoint of he was for standing up for Roe v. Wade before he was against Roe v. Wade?” he said, adding: “He was for Race to the Top, he’s for Obamacare, and now he’s against it. I mean, we’ll wait until tomorrow and — and — and see which Mitt Romney we’re really talking to tonight.”

Romney shot back, “Governor Perry, you wrote a book six months ago. You’re already retreating from the positions that were in that book.” He continued, “Well, in that book, it says that Social Security was forced upon the American people. It says that, by any measure, Social Security is a failure. Not to 75 million people. And you also said that — that Social Security should be returned to the states. Now, those are the positions in your book.”

Romney also had to defend his record on health care in Massachusetts. Perry cited a 2010 paper written by R. Glenn Hubbard, an economist who Romney announced this month would help lead his team of economic advisers.

In the article, published in the Forum for Health Economics and Policy, Hubbard and two co-authors noted the similarity of the Massachusetts plan to the national health-care law Obama signed in 2010. Romney has distanced himself from the federal law.

“The plan’s main components are the same as those of the new health reform law, the effects of the plan provide a window onto the country’s future,” the paper says.

Romney said he never saw the program as a model for the nation, only a solution to his state’s problems.