Early on in the period-piece thriller “Beirut,” Jon Hamm’s suave and glib diplomat is asked to explain to a newcomer what the title city is like — so he launches into his go-to story in which he compares Beirut to a building occupied by tenants who don’t really trust one another, and then one rainy night a stranger comes knocking at the door, and …

And … some other stuff happens.

You see, this is the kind of movie where even the supposedly simple analogies are complicated.

Directed with skillful precision by Brad Anderson and scripted (more than 20 years ago, as a matter of fact) by the premium-talent Tony Gilroy (“Michael Clayton,” the “Bourne” trilogy, “Rogue One”), “Beirut” is a tense and ever-twisting rescue mission story set against the backdrop of a city ravaged by violence perpetuated by multiple entities, all of them concerned only with their self-interests, the innocent citizens be damned.

On one or two or maybe even three occasions in this story, I found myself flipping through the mental notebook to remind myself of the significance and/or allegiances of a supporting player who pops up after an extended absence. There are a LOT of moving parts in this story.

But eventually the major pieces of the jigsaw puzzle fit neatly and firmly into place.

Jon Hamm delivers one of his best film roles as Mason Skiles, a handsome, hotshot American diplomat living with his beautiful and charming wife Nadia (Leila Bekhti) in Beirut in 1972, when the city had an edgy, cosmopolitan vibe. When we meet Mason, he’s hosting a cocktail party for movers and shakers, working the room with the grace of a dancer, filled with energy and purpose and LIFE.

Cut to a decade later. His world shattered by a violent tragedy, Mason is back in the States, scraping out a living (and wasting his considerable talents and expertise) as a labor negotiator in the Boston area and crawling inside of a bottle every night. He has been forgotten by everyone who once knew and cared about him, and that’s by design.

When Mason is offered a speaking engagement in Lebanon, it’s pretty obvious there’s going to be more to the trip than addressing college students. It’s more of a summons from the past than a request.

When he arrives in Beirut, he sees a city laid waste by years of civil war and bearing little resemblance to the one he left behind. It would break his heart if his heart wasn’t already fractured beyond repair.

Mason soon learns the true purpose of his trip: his onetime best friend Cal (Mark Pellegrino), a top-level CIA operative, has been kidnapped, and the terrorists holding him hostage have specifically requested Mason as a negotiator. (The reason for this stems back to when Mason was living in Beirut, and let’s leave it at that.)

Rosamund Pike in “Beirut.” | BLEECKER STREET

Rosamund Pike (“Gone Girl”) is the field agent Sandy Crowder, who has been assigned the role of babysitting the perpetually well-lubricated Mason. Shea Whigham (“Boardwalk Empire”) is Gary Ruzak and Dean Norris (“Breaking Bad”) is Donald Gaines, State Department higher-ups who don’t bother to disguise their disdain for the undisciplined washout Mason and their frustration he’s even along for this mission. (Three excellent performances.)

The U.S. desperately wants Cal back — mostly out of fear he will give up crucial information. Mason tries to stay sober and get his head in the game in order to save his old friend. Crowder, Ruzak and Gaines work separate agendas that may or may not be in line with the officially stated mission to rescue Cal.

It’s all sorted out on a sweaty, dusty, sometimes blood-soaked and brutally violent playing field. Just about every character in “Beirut” is extremely smart and cunning — but maybe not as smart and cunning as someone else in the room (or on the rooftop or lurking in the shadows).

For a guy who’s been out of the game for a decade and drinks so much he can barely stay awake even when the stakes are life and death, Mason transitions into a foreign espionage superhero in rapid fashion.

Ah, but that’s the genre. The stakes in “Beirut” are deadly serious, but the film itself is not presented as a major political statement or commentary beyond: The more things change, the more they stay the same. This is an old-fashioned spy thriller, and as such it succeeds.

★★★

Bleecker Street presents a film directed by Brad Anderson and written by Tony Gilroy. Rated R (for language, some violence and a brief nude image). Running time: 109 minutes. Opens Wednesday at local theaters.