Five months ago, Texas Gov. Rick Perry launched his presidential campaign to great expectations. Thursday morning, plagued by missteps and humbled by the voters, he called it quits, quietly returning home to wonder what might have been.

He was perhaps the biggest of big figures when he announced his candidacy in this state on a Saturday in August. He seemed to be the ideal candidate to emerge from the crowded field to become the darling of conservatives and the principal alternative to former Massachusetts governor Mitt Romney.

He entered as the longest-serving governor in Texas history, a politician who had never lost a race, a governor whose state in recent years had created more jobs than all the other states combined. He seemed to have perfect pitch with the tea party movement that had reshaped his party and he had a financial network that could raise big money quickly.

Certainly, Romney’s campaign believed all that and quickly prepared to take Perry down. It was hardly necessary. For Perry, almost nothing went to form, beginning with a series of underwhelming debate performances that came to define him in ways he could never overcome.

He left the race after finishing in single digits in both Iowa and New Hampshire and facing the prospect of mirror finish here on Saturday. He became a textbook example of why candidates need months and sometimes years of preparation. Even worse, his campaign became a model of dysfunction, infighting and intrigue as a new group of advisers that had been grafted onto his longtime team never came together.

Perry will be left to reflect on whether it could have been different, and he no doubt believes he deserved better. In the final days of his campaign, long after he had any hope of resurrecting his chances of winning the nomination, he was better. He showed flashes of the skilled retail campaigner he was reputed to be. His last debate, in Myrtle Beach on Monday night, was one of his best.

But it was too late. As his advisers and loyalists acknowledged in the days leading up to his withdrawal, Perry was proof of the adage that you never get a second chance to make a first impression — and his first impression was politically disastrous.

The debates proved his undoing.

Under fire, Perry maladroitly defended a Texas law that provided in-state college tuition to high school graduates who were residents of the state and children of illegal immigrants. “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,” he said.

The immigration issue caught his advisers totally unaware. In Texas, the law providing in-state tuition had been long settled and accepted. Elsewhere, among conservative Republicans, it was toxic. But Perry’s team had not adequately researched the potential impact, nor was the candidate prepared for the reaction to his unfortunate choice of words, which outraged conservatives.

A worse moment was yet to come. When the candidates met in Michigan in early November, Perry lost his train of thought as he was trying to name the three federal agencies he wanted to eliminate. Despite prompts and assists from his rivals, he stammered to one of the most embarrassing moments in the history of presidential debates, acknowledging that he could not remember the third agency. After citing the Education and Commerce departments, he froze. “I can’t [remember],” he said plaintively. “The third one, I can’t. Sorry. Oops.”

The “oops moment” was etched in public consciousness and came to symbolize Perry’s flagging campaign. He made a heroic and good-hearted effort to repair the damage, heading into the spin room moments after the debate to acknowledge his mistake. “I’m sure glad I had my boots on because I sure stepped in it out there,” he said.

The Perry campaign long ago budgeted its advertising dollars and ground operations throughout South Carolina, and the candidate, after a momentary pause after Iowa, jumped into the race here with the intention of campaigning through Saturday.

But by Wednesday afternoon, in consultation with his wife, Anita, he decided to quit and endorse former House speaker Newt Gingrich.

“As I have contemplated the future of this campaign, I have come to the conclusion that there is no viable path to victory for my candidacy in 2012,” he said gamely in a nondescript conference room in his North Charleston Hotel before a throng of reporters and cameras.

Although vanquished, he tried to hold his head high as he prepared for the trip home. “The journey leads us back to Texas,” he said, “neither discouraged nor disenchanted, but instead rewarded for the experience and resolute to remain in the arena and in the service of a great nation. Our country needs bold leadership and real transformation.”

In that, there were hints of another run for president, or so said Ray Sullivan, Perry’s communications director. He volunteered to reporters Thursday that, if Republicans don’t win the White House in November, Perry might try again in 2016.

Had Perry told him to say that? Sullivan responded: “I told him it was my intention to talk about that and I didn’t get dissuaded.”