WASHINGTON — President Barack Obama is leaving office as Chicago is in the spotlight not only as the city that spawned the two-term president but also as a murder capital of the United States.

Obama comes to Chicago on Tuesday to celebrate his achievements in his farewell address — a hat-tip to the adopted hometown of the nation’s first African-American president.

He’ll have a string of national successes with local impact to brag about in his McCormick Place address, from improved access for Illinoisans to health insurance, to an economy stronger than the one he inherited, to increased conservation of natural resources.

But there’s another stark reality, too. The city struggled with crime and police misconduct in black communities for years before Obama moved to Chicago. And even with a Chicagoan in the Oval Office, no magic wand could make the city’s most pressing problems go away.

And, on Thursday, Obama found himself deploring a horrible race-related crime on Chicago’s West Side: A Facebook video captured the torture of a schizophrenic, white 18-year-old. Four African-Americans are facing charges.

One enduring takeaway from the Obama presidential years is this: Not even a president who embraced all things Chicago and a first lady raised in South Shore — both acutely aware of the interlocking realities of poverty, racism, bad policing and the easy availability of guns — could prevent Chicago’s surge in killings. The number of murders in Chicago in 2016 hit 780— the most in a year since 1996.

RELATED STORY: Sweet: Obama’s legacy — he will always be Chicago’s president

Through their years in Washington, the Obamas kept an eye on Chicago’s crime problems, even if it was mostly from a distance. The Obama residence at 5046 S. Greenwood Ave. never became the Chicago White House — a sore point with some people in the early years.

Responding to that, Michelle Obama told reporters in 2010 that the busy schedules of the first couple’s daughters — Malia, then 11, and Sasha, who was 8 — precluded coming home often. “Nothing personal,” she said.

Derrion Albert was killed in 2009 outside Fenger Academy High School.

Derrion Albert was killed in 2009 outside Fenger Academy High School.

During Obama’s first year as president, the White House intervened after Derrion Albert, a 16-year-old Fenger Academy High School student, was beaten to death by other teens — a murder, captured on a cell phone video, that touched off a national uproar.

Obama dispatched Attorney General Eric Holder and Education Secretary Arne Duncan — the former Chicago Public Schools chief — in October 2009 to meet with Chicago students, religious leaders and then-Mayor Richard M. Daley and other officials. Duncan brought with a $500,000 grant for Fenger to help create a safer environment.

The crime situation only grew more intense as the years passed, and police shootings became a flashpoint in Chicago, as well as in Ferguson, Missouri, and Baltimore.

In 2013, the president and first lady put a spotlight on gun deaths in Chicago after being shaken by the killing of a teenage girl named Hadiya Pendleton, who was caught in gang crossfire at Harsh Park near their Kenwood home on Jan. 29, 2013.

Hadiya Pendleton.

Hadiya Pendleton.

Only a week earlier, the 15-year-old Chicago high school student had traveled to Washington for public festivities surrounding Obama’s second inauguration, on Jan. 21, 2013.

The Obamas’ daughters were 14 and 11 by then. Mrs. Obama returned home for Hadiya’s Feb. 6 funeral.

Hadiya’s parents, Cleopatra Cowley-Pendleton and Nathaniel Pendleton Sr., were her guests for Obama’s Feb. 12 State of the Union speech.

Just two months before that, Obama was consoling the families of victims of the shooting massacre at Sandy Hook Elementary School in Newtown, Conn. Using his State of the Union to try to shame Congress into at least taking a vote on measures to curb gun violence, he invoked Hadiya’s name.

Cleopatra Cowley-Pendleton, left, mother of teenage shooting victim Hadiya Pendleton with Michelle Obama in the joint congressional box of the U.S. House of Representatives before the 2013 State of the Union address. | ABC Network News

Cleopatra Cowley-Pendleton, left, mother of teenage shooting victim Hadiya Pendleton with Michelle Obama in the joint congressional box of the U.S. House of Representatives before the 2013 State of the Union address. | ABC News

“She was shot and killed in a Chicago park after school, just a mile away from my house,” Obama said. “Hadiya’s parents, Nate and Cleo, are in this chamber tonight, along with more than two dozen Americans whose lives have been torn apart by gun violence.”

Three days later, Obama was back in his old Chicago neighborhood, at Hyde Park Academy, 6220 S. Stony Island Ave., to push his gun proposals.

Before that speech, Obama met with young men from the school who were participants in a program created in Chicago called Becoming a Man.

“When I screwed up,” Obama told them, “the consequences weren’t as high as when kids on the South Side screw up.”

Michelle Obama returned to Chicago that April 10 to speak at an event organized by Mayor Rahm Emanuel — who was Obama’s first White House chief of staff and succeeded Daley in 2011 — for backers and donors to his youth anti-crime programs.

“Hadiya Pendleton was me, and I was her,” said the first lady, who was raised in South Shore at 7436 S. Euclid Ave. “But I got to grow up.”

Afterward, she headed to Harper High School, 6520 S. Woods St., to hear from students whose lives were touched daily by violence. She invited them to the White House and hosted them that June.

On Feb. 27, 2014, Obama launched a White House program called My Brother’s Keeper to help boys and young men of color overcome the disproportionate share of obstacles they face. Introducing Obama that day at the White House was Christian Champagne, one of the Hyde Park high school students Obama had met with in 2013.

Today, Champagne, 21, is a sophomore at Western Illinois University, majoring in business. He’s had a hardscrabble life, working to help his mom pay the rent. Meeting Obama, Champagne said, provided him with “inspiration that because of where I come from should not be the limitation that defines me, that anything is possible, and I can always better myself.”

The 2014 fatal shooting of teen Laquan McDonald by a Chicago cop would open yet another new chapter of tense relations between police and the city’s black communities. As a result, in December 2015, Attorney General Loretta Lynch launched a civil rights investigation of the department.

“When community members feel that they are not receiving that kind of policing, when they feel ignored, let down or mistreated by public safety officials, there are profound consequences for the well-being of their communities, there are profound consequences for the rule of law and for the countless law enforcement officers who strive to fulfill their duties with professionalism and integrity,” Lynch, echoing Obama’s views, said in announcing the probe.

The Justice Department and the city are racing to reach an agreement before Obama leaves office.

There’s no question regarding violence that the Obamas have tried. Republicans in Congress have blocked gun measures that Emanuel and others said would help curb the shooting in Chicago. Obama signed executive orders dealing with guns to do what he could.

“He’s president of the United States, not the president of Chicago,” said Duncan, who is back in Chicago now as a managing partner of the Emerson Collective, a non-profit where he works on ways to help at-risk kids.

“I think [Obama] came to realize, sadly, the limits of the presidency when it comes to solving these problems,” said Sen. Dick Durbin, D-Ill., who early on encouraged his junior Senate partner to run for president in 2008. “I talked to him over and over again about this, trying to come up with a federal answer or a single answer that can have dramatic impact. It’s almost as difficult as Syria.”

After he leaves the White House, Obama will continue his work with My Brother’s Keeper under the flag of a non-profit organization his team created — the My Brother’s Keeper Alliance. Duncan and John Rogers — founder of Ariel Investments and a longtime friend of the Obamas — are on the group’s board.

Last month, at his final Keeper event, Obama said, “This is something that I will be invested in for the rest of my life.”