Screenwriter Tony Gilroy was the man behind the Jason Bourne series, but his screenplay for “Beirut” is a rather different kind of espionage tale, more like Le Carré—a pretty good variant on the sort of story represented by “The Spy Who Came in From the Cold.”

The film opens with a prologue set in 1972 Lebanon, where Mason Skiles (Jon Hamm) is a U.S. diplomat is hosting a party with his wife Nadia (Leila Bakhti). Mason goes from guest to guest, offering his views on the factional politics of the country and how they can be dealt with. Also circulating the room is Karim (Yoav Sadian Rosenberg), a Palestinian orphan the Skiles have effectively adopted, who is happy to serve as a waiter.

The gathering is soon disrupted by the arrival of Mason’s pal Cal Riley (Mark Pellegrino), who informs him that agents are about to arrive to escort Karim away for interrogation. They’ve learned that he has a brother, a notorious terrorist named Abu Rajal (Hicham Ouraqa), who’s now in Beirut. Skiles objects, but before the boy can be removed, a masked gang enters with automatic weapons ablaze, whisk Karim away, and leave several people dead.

Ten years later Skiles is working as a labor negotiator in the States, spending his off hours in bars. It’s I one of them that he’s approached after a rough day by an old acquaintance who offers him, on behalf of the CIA, a large payment to fly immediately to Beirut. He demurs, but is told it’s a request that cannot be denied. And so Skiles finds himself returning to a place he never wanted to see again, supposedly as a guest lecturer at the American University.

His real mission, however, is to negotiate the release of Cal, who’s being held hostage by a shadowy Palestinian group whose leader asked specifically for him to serve as mediator. The reason for that strange request becomes clear when Mason learns that the kidnapper is Karim (now played by Idir Chender), who offers to exchange the American for his brother, whom he believes is being held by the Israelis.

Of course, virtually everyone involved in the operation has an agenda of his own. For Skiles, it offers a chance to bring closure to a traumatic episode he’s never gotten over. It gives a desperate Karim an opportunity to get his brother back. For the American intelligence officers, CIA head Donald Gaines (Dean Norris) and Embassy security head Gary Ruzak (Shea Whigham), it presents a slim chance to retrieve an asset that could do them enormous damage –or, failing that, turning the situation to their own advantage. The avuncular American ambassador (Larry Pine) wants everything handled with a minimum of upset to the applecart. Skiles’s minder, Sandy Crowder (Rosamund Pike), has reasons of her own for wanting Cal back. Meanwhile both the Israeli government, represented by a military attaché (Alan Aboutboul), and the PLO, represented by one of its ministers (Ahmed Said Arie), try to control affairs to reach very different goals.

What emerges is a portrait of cynicism, corruption, political fragmentation and violence that foreshadows –as a newsreel montage at the close shows—the Israeli invasion of 1982 that brought even more disorder to the war-torn country.

“Beirut” is set against a chaotic historical backdrop (listening to Hamm’s chatter in the opening party scene will be helpful in that regard), but Gilroy manages to keep what’s happening in his fictional world reasonably clear, though it must be admitted that a bombing attack during Skiles’s university lecture has a curiously muted aftermath. On the other hand, the final act has a rousingly exciting chase that turns genuinely tense as a prisoner exchange is attempted, and that’s topped by a sudden burst of action including the intervention of a surprising character. It’s all satisfyingly taut in the old-fashioned, almost genteel way typical of spy movies from decades past. (In that respect it’s a fitting companion piece to “Red Sparrow.”)

And it represents a solid leading-man turn for Hamm, who’s has some difficulty translating his small-screen success in “Mad Men” onto the big one but shows considerable presence here under Brad Anderson’s taut direction. Pike’s role offers less scope, but she does what is required well enough, and the entire supporting cast provides colorful, vivid turns, though it’s difficult not to be distracted by Norris’ hairpiece. The movie technically accomplished, with cinematographer Bjorn Charpentier giving the Moroccan locations a drab, brown appearance enhanced by Arad Sawat’s production design and what appears to be some effective effects work to accentuate a look of widespread destruction and devastation to scenes shot in Tangiers. Andrew Hafitz’s editing shifts efficiently from the more subdued sequences to the action ones, while John Debney contributes an appropriately moody score that takes on a sharper tone as needed but also acknowledges when silence is preferable.

Visiting the once-beautiful city of Beirut—the Paris of the Middle East, it was said—in the real world might a chancy proposition at the moment, but a couple of hours at “Beirut” is time well spent.