It’s an odd coincidence that two of the year’s best American films are ­serious-minded comedies that open the same day. Even stranger is that one of them is the season’s second attempt to combine a Washington drawing-room comedy with a cautionary tale about the “war on terror.” Although it’s thematically similar, Charlie Wilson’s War thoroughly outclasses The Walker, in part because it knows what it’s talking about but also because the quality of its talk is so much higher. Scripted by Aaron Sorkin, who put in a few years at The West Wing after 1995’s bland The American President, Charlie Wilson’s War is a giddy romp about a great CIA triumph that, along the way, led to a catastrophic failure.

Based on George Crile’s nonfiction book of the same name, Charlie Wilson’s War is set during the Reagan era but pays little attention to the White House. It’s about a U.S. representative, liberal by Texas standards, who devises a plan to foil the Soviet invasion of Afghanistan. He requires the help only of a right-wing socialite and a rogue CIA agent—plus Pakistani authorities, Egyptian and Israeli arms dealers, and the Afghani mujahedeen. Charlie Wilson (Tom Hanks) is introduced while soaking in a Las Vegas hot tub with a Playboy playmate and two strippers, taking a pitch for a Dallas-like soap opera set in Washington. Wilson is an inveterate party boy, but his attention is seized by what’s on a nearby TV: “Gunga Dan” Rather, reporting from Afghanistan. The scene is typical of the script’s efficiency, establishing both essential aspects of Wilson’s character in a few strokes.

The congressman’s interest in Afghanistan is further piqued by sometime lover Joanne Herring (Julia Roberts), a rich reactionary with connections in Pakistan. She arranges a tour of that country, where Wilson cluelessly asks the country’s Muslim president (Om Puri) for a whiskey, and then tours a refugee camp near Peshawar with aide Bonnie Bach (Amy Adams), who’s foremost in a bevy of pretty assistants. Soon Wilson has called a meeting with rough-edged CIA man Gust Avrakotos (Philip Seymour Hoffman, as exuberantly cranky here as he is brooding in The Savages); a classic disgruntled office worker, Avrakotos has just spectacularly kissed off one boss but has a new gig helping to “kill Russians.” Over time, Wilson gets the funding for the mujahedeen increased from $5 million to $1 billion, while Avrakotos shows him how to flood Afghanistan with anti-Soviet weapons, none of them made in the U.S. (a Cold War no-no).

If Hanks clutches his nice-guy persona a little too tightly—making Wilson’s sexism seem boyish rather than grown-up and ­predatory—he delivers Sorkin’s zingers with verve. The essence of this characterization is that Wilson is not a smoothie, at least in the realm of international affairs, but a man whose earnestness trumps his inappropriate remarks. (“For the love of Christ,” he implores some Israeli weapons merchants.) Hoffman’s Avrakotos is a peppery delight, even when playing scenes whose slapstick quotient is a little too high. Director Mike Nichols matches the screenplay’s gait, handling nine years of secret war in about 90 minutes.

This pace gives Charlie Wilson’s War little time to note what happened next, an oversight some observers have attributed to timidity. Perhaps the movie is too subtle for those who don’t know where Osama bin Laden took up residence in the ’90s, but for well-informed viewers the movie offers the optimal measure of foreboding. As Wilson tells Herring, who sees the almighty and the U.S. as roughly synonymous, “Sooner or later, God’s going to be on both sides.” No spending bill, and no amount of Texas gumption, can alter that rueful conclusion.