Charlie Wilson, a 12-term Texas congressman who was best known for his playboy ways until he masterminded a covert effort to funnel billions of dollars in arms to Afghan rebels fighting the Soviets in the 1980s, died Wednesday in Lufkin, Tex. He was 76.

Jack Gorden Jr., the mayor of Lufkin, confirmed the death. Memorial Medical Center-Lufkin said the preliminary cause of death was cardiopulmonary arrest. Mr. Wilson had a heart transplant in 2007.

Mr. Wilson’s exploits to provide as much as $5 billion in arms to Afghan rebels were the subject of a book and the 2007 movie “Charlie Wilson’s War,” directed by Mike Nichols. Tom Hanks portrayed Mr. Wilson and Julia Roberts played Joanne Herring, the conservative Houston socialite who first interested Mr. Wilson, a Democrat, in aiding the Afghans.

A former president of Pakistan, Gen. Mohammad Zia ul-Haq, said it was hard to understate Mr. Wilson’s role. “All I can say is, ‘Charlie did it,’ ” he said on “60 Minutes” in 1988.

It was an unusual role for a congressman representing an unworldly East Texas district. From 1973 to 1996, Mr. Wilson kept his seat by balancing liberal views on many domestic issues with a hawkish stance on foreign policy and paying close attention to his constituents’ needs.

Until his secret role in Afghanistan became the stuff of Hollywood, Mr. Wilson’s fame was pretty much summed up by his nickname, “Good Time Charlie.” An article in Texas Monthly in 2004 said he gave his girlfriends nicknames like Snowflake, Tornado and Firecracker.

Mr. Wilson was able to help the Afghans from his seat on the House Appropriations Committee and from another on its subcommittee on foreign operations.

The Soviets had invaded Afghanistan in 1979, invited by the pro-Communist government there in the face of an insurgency.

After he visited a refugee camp in Pakistan at the urging of Ms. Herring and saw wounded and maimed Afghan guerrilla fighters, Mr. Wilson vowed to help them and became a key figure in Congress for doing so, overtly pushing for humanitarian aid and covertly obtaining military help, a risky endeavor against a rival superpower. He often gathered his colleagues’ support by voting for military contracts that would serve their districts.

From a few million dollars in the early 1980s, support for the resistance grew to $750 million a year by the end of the decade. The financing was funneled to Afghanistan in secret by Mr. Wilson and other lawmakers.

The help went beyond money. When the Soviets deliberately killed camels and mules to cripple the Afghan fighters’ supply lines, he flew in Tennessee mules. When the Central Intelligence Agency refused to provide the guerrillas with field radios for fear that mujahedeen transmissions would be picked up by the Soviets, he sent an aide to Virginia to buy $12,000 worth of walkie-talkies from a Radio Shack outlet.

Particularly helpful were Stinger missiles from the United States, which were used to shoot down Russian helicopters and became what many consider a decisive factor in wearing down the Soviets. By February 1989, the Soviets had withdrawn and the United States ended its support.

In later years Mr. Wilson insisted that the United States had not made a mistake by supporting the Afghan rebels, among them Osama bin Laden and the Islamists who would form the Taliban regime. He said if the United States had helped rebuild Afghanistan, it would have remained stable and not become a safe haven for Al Qaeda.

An error has occurred. Please try again later.

You are already subscribed to this email.

Charles Nesbitt Wilson was born in Trinity, Tex., where his father was an accountant for a lumber company, on June 1, 1933. He told about his first political experience in the book from which the movie was made, “Charlie Wilson’s War: The Extraordinary Story of the Largest Covert Operation in History” (2003) by George Crile.

Charlie was 13 when his dog strayed and a neighbor apparently fed it something that contained crushed glass. The boy first doused the man’s garden with gasoline and set it on fire. He then realized that the neighbor was a City Council member and used his learner’s permit to drive black voters to the polls to vote against him. The neighbor lost his seat by 16 votes.

Mr. Wilson attended the Naval Academy at Annapolis and graduated in 1956. He served four years in the Navy and went back to Texas, where he was elected to the State House of Representatives and then to the State Senate.

In 1972, he ran successfully for Congress, where he outmaneuvered a fellow Texan for a seat on the Appropriations Committee as well as a slot on its subcommittee on foreign operations.

Mr. Wilson is survived by his wife, the former Barbara Alberstadt, and his sister, Sharon Allison.

His rowdy behavior produced sensational headlines over the years. There were at least two midnight car crashes. He was investigated for cocaine use, and election-expenditure irregularities resulted in a $90,000 fine.

In an interview with Washingtonian magazine in 1996, Mr. Wilson said Texas voters put up with his antics in part because of the vicarious thrill they got in watching him. He added that he did not lie or whine when caught.

“I just say, ‘Well, yeah, I guess I goofed again’ and go about my business,” he said. “Those good Christians, you know, believe in the redemption of sin.”

When he announced his resignation in 1995, saying the job was not fun anymore, Mr. Wilson thanked his constituents for their tolerance.

“He was our favorite town character,” Mayor Gorden said. “He was a rascal but our rascal.”

A version of this article appears in print on February 11, 2010, on Page B19 of the New York edition with the headline: Charlie Wilson, Texas Congressman Linked to Foreign Intrigue, Dies at 76. Order Reprints|Today's Paper|Subscribe