It might be hard to imagine after last week’s GOP presidential slugfest, but there was a time not too long ago when a group headed by Mitt Romney quietly—and a judge says illegally—helped Rick Perry’s political career in Texas and set the stage for his new nemesis to rise on the national stage.

Known mostly by Texas political insiders, the allegations gleaned from court files have mostly escaped national attention as Romney and Perry quickly transform the 2012 GOP presidential nomination into an intense two-man race that has left other contenders like Michele Bachmann and Jon Huntsman in the rearview mirror.

And what hasn’t emerged before are court files reviewed by The Daily Beast stating that Romney was personally aware of the origins of the $1 million donation from a Texas homebuilder at the heart of the controversy, and that he discussed it with Perry’s campaign aides.

In the fall of 2006, Perry was engaged in an unexpectedly tight reelection race for Texas governor. Romney, a fellow governor from Massachusetts, was running the Republican Governors Association, helping GOP incumbents try to keep their jobs in a tough election swayed by discontent over Iraq, Bush fatigue, and economic uncertainty in an unstable mortgage market.

Perry was in need of fresh funds for advertising in the final weeks, and he had the perfect source: millionaire Houston homebuilder Bob Perry, the man who just two years earlier had helped underwrite the Swift Boat attack ads that damaged John Kerry’s standing among veterans in the 2004 presidential race that tipped to George W. Bush. (The Perrys are not related.)

If the governor took money directly from the homebuilder late in the race, he might resurrect questions over his close ties to Bob Perry, who was already one of Rick Perry’s biggest benefactors and had been tied to his controversial 2003 decision to create a commission to regulate complaints against homebuilders. Rick Perry also had run ads earlier in the campaign accusing his Democratic competitor of being addicted to trial-lawyer money, and his advisers didn’t want the issue to boomerang.

Legally, Bob Perry was free to give as much as he wanted under Texas law to the governor and to the RGA, and he has never been accused of any wrongdoing. Rick Perry and the RGA, however, were subsequently sued in state court for the way they handled the donation.

According to court records, the money from Bob Perry sent to the RGA was routed to the governor’s campaign in two $500,000 chunks. The last check for $500,000 was personally delivered to Rick Perry in Washington by Romney’s executive director at the RGA, Phil Musser, the court records say.

The arrangement violated Texas election-disclosure law, a Travis County judge ruled last year, because the RGA wasn’t registered in Texas as a political committee and did not file a report disclosing its contribution until well after the election, essentially depriving voters of knowing about the donation until after they voted.

The arrangement violated the law’s intent to “limit undue influence over elections and fully disclose information related to contributions and expenditures for elections in this state,” the court ruled on Aug. 31, 2010.

Spokesmen for Romney and Rick Perry did not return repeated requests seeking comment. Officials for the RGA also did not return calls seeking comment. The group is appealing the judge’s ruling and has said Bob Perry’s money was not specifically earmarked for Rick Perry, portraying the decision to donate to the governor as having been made after the homebuilder’s check had already been sent to the RGA.

Anthony Holm, a spokesman for Bob Perry, told The Daily Beast that the homebuilder routinely donates to the RGA. “Bob Perry had supported the RGA long before Governor Perry’s 2006 campaign, and continued long after. This is Bob Perry’s normal donation behavior with the RGA. The RGA controls [contributions to] the 20-plus governors whom they support,” Holm said.

Rick Perry’s campaign has denied in the past that it did anything wrong but settled its role in the lawsuit by making a $427,000 payment in 2010, court records show.

The governor ultimately cruised to victory in November 2006, but with just 39 percent of the popular vote in a race in which both major-party candidates saw their support cut by independent candidates.

Two months after the election, Perry’s main Democratic opponent, Chris Bell, got wind of the arrangement with the RGA and sued in state court, alleging that the donation arrangement evaded Texas disclosure laws.

“No one in Texas, or anywhere else for that matter, could find out who was underwriting the RGA’s contributions to the Perry campaign prior to the election,” Bell’s lawsuit alleged. “This is a direct violation of Texas law.”

Long after the national press lost interest in Perry’s reelection victory, Bell’s lawyers took depositions and subpoenaed documents exposing exactly how the money went from Bob Perry to the RGA, and then to Rick Perry.

Romney wasn’t named as a defendant, though he was chairman of the RGA when the donation occurred. In a pleading filed with the court, attorneys for Rick Perry’s campaign acknowledged that two aides to the Texas governor met with the then–RGA chairman to discuss the donation.

“During that meeting,” the pleading states, “Gov. Romney stated that, on behalf of the RGA, he was about to accept $1 million from an individual Texas contributor. Gov. Romney did not identify who the contributor was, and [Texans for Rick Perry] had no knowledge prior to that time that any individual was planning to contribute $1 million to the RGA. “

After the meeting, Rick Perry’s aides confirmed that the donor was Bob Perry, and the governor’s campaign asked that the homebuilder’s money to the RGA be directed to Texas, according to the filings.

The lawyer for Bell says there was ample evidence that the transactions between RGA and the Perry campaign also would have violated campaign money-laundering laws, but his client chose instead to pursue a violation of campaign-disclosure laws in civil court, where the defendants would face the possibility of stiffer penalties than the maximum criminal charge of a third-degree felony, punishable by two to 10 years in prison and up to $10,000 in fines.

“Had we chose to bring the money-laundering [charge], or what we call giving money in the name of another—where you disguise the donation by running it through a PAC [such as the RGA]—we could have brought that. But we didn’t really need it,” attorney Buck Wood says.

Eventually, Bell won an out-of-court settlement in 2010 from Rick Perry for $427,000. The local judge ruled that the RGA should pay a $2 million penalty, a decision the group is appealing.

The episode is noteworthy not only for Romney’s prior help to his now-rival Perry, but also because it highlights that both men have played the special-interest-money game while trying to portray themselves as Washington outsiders now in the 2012 campaign.

Bob Perry burst onto the national scene in 2004, when it was disclosed he helped fund the controversial but influential Swift Boat ads that challenged Kerry’s Vietnam War record and had a profound effect on the 2004 presidential campaign.

Since then, Bob Perry has given at least $7 million to the GOP super-money group American Crossroads—run by former Bush strategists Karl Rove and Ed Gillespie—that helped Republicans regain control of the U.S. House in the 2010 elections.

In Texas, Bob Perry has long been a proponent of tort reform, particularly in relation to protecting businesses from trial lawyers.

In 2003, Rick Perry championed creating the Texas Residential Construction Commission, a state agency that was supposed to protect homeowners from bad builders but instead became a haven for protecting builders from complaints.

The original legislation was written by the housing industry with the help of John Krugh, a lobbyist for Bob Perry’s homebuilding company in Houston. In September 2003, state campaign records show, Bob Perry wrote a $100,000 political check to Rick Perry. The governor then named Krugh to the commission.

The agency was criticized as being ineffective and was abolished in 2009 by the Texas Legislature. A year later, a jury ordered Bob Perry’s company and a home-warranty firm to pay $58 million to two homeowners who alleged that Perry’s company refused for years to fix problems with their defective home. The company settled out of court.

The Perry-Perry relationship is just one of several emerging as the national media—and Rick Perry’s rivals, stunned by his rapid ascent to the head of the GOP field—begin digging into his relationship with donors and special interests.

During last week’s Tea Party debate in Tampa, Bachmann cited a connection between a lobbyist and Perry’s program to vaccinate young girls against a sexually transmitted virus.

In 2007, Perry bypassed the Texas Legislature and his own socially conservative views when he signed an order making Texas the only state in the nation to require sixth-grade girls to receive a vaccination against human papillomavirus, which can cause cervical cancer. Perry’s former chief of staff, Mike Toomey, was a lobbyist for Merck, the manufacturer of the vaccine. Lawmakers repealed the order when conservative Christians protested.

A calendar obtained under Texas’s open-records laws shows that Perry’s chief of staff met with the governor’s budget director and three members of his office for an “HPV Vaccine for Children Briefing” the same day that Merck’s political-action committee donated $5,000 to Perry’s gubernatorial campaign.

Earlier this year, Perry came under scrutiny for his relationship with Texas billionaire Harold Simmons, who has donated $3 million to the governor’s campaign and is building a low-level nuclear-waste dump in western Texas.

The state’s Low-Level Radioactive Waste Disposal Compact Commission took action, allowing Simmons’s dump to accept nuclear waste from around the country. Six of the commission’s seven members were appointed by Perry.