Tom Hanks stars in “Captain Phillips.” (Columbia Pictures)

“Captain Phillips,” opening Friday, is based on the true story of the 2009 hijacking of the Maersk Alabama and the subsequent kidnapping of the ship’s captain, Richard Phillips. Most of the film’s audience, of course, will be familiar with elements of the story and its resolution, but the film still surprises with the nuanced shading it gives the characters of four young Somali pirates who take over an American freighter.

“It dares to humanize them,” says Tom Hanks, who stars as Phillips. “They’re criminals, they’re thugs, there’s no doubt about it, but it puts it all in the realm of human behavior that becomes somehow more recognizable.”

That’s particularly true for Barkhad Abdi, who plays Muse, the leader of the gang of pirates. Abdi was born in Mogadishu, Somalia, moved to Yemen with his family in 1991 when he was 6, and immigrated to the Minneapolis area at age 14. (Abdi, who still lives there, was driving a limo when the casting call reached the area’s large Somali community.)

“He is a bad guy,” Abdi says of Muse. “But I understand why he was bad. I was 6 when [Somali’s civil] war started, so I’ve seen killing, all that stuff. It’s still stuck in my mind. I was fortunate enough to have parents who got me out so I could be a better man, make something of myself. In a lot of ways, that could be me.”

And in some ways, it could be us.

“Just examining the grand structure of piracy, with these criminal bosses, that’s almost recognizable as our organized crime,” says Hanks, noting that this system of piracy basically exploits kids who go out and steal the money, only to turn the vast majority of it over to the warlords who rule their villages.

For many young Somali men, especially along the coastline, piracy is one of the few viable job opportunities. In “Captain Phillips,” Muse points out that they would be fishermen if it weren’t for the American and European trawlers that overfished the area.

That said, the pirates are still the villains of the piece.

“They are not sympathetic characters,” Hanks says. “Richard Phillips never thought, ‘Hey, these are nice guys who got a bum deal.’ These guys are poor and they live in a country that has been decimated by poverty, by corruption, by violence and by hopelessness. I think [the film] just raises the level of everything without ever turning into ‘oh, those poor pirates.’ ”