HOUSTON — The St. Louis Rams are moving back to Los Angeles and the San Diego Chargers will have the option to join them in a compromise approved by NFL owners Tuesday night.

The Oakland Raiders, who also wanted to move to the area, could take the Chargers’ spot if they stay in San Diego, Commissioner Roger Goodell said.

The Chargers and Raiders wanted to share a new stadium in Carson, California, and the Rams wanted to move to nearby Inglewood, but neither option got the 24 votes needed for approval. After a day of negotiations in Houston, the owners approved the St. Louis move 30-2, with a first option for San Diego to share the $1.8 billion stadium Rams owner Stan Kroenke is building in Inglewood, California.

The decision ends the NFL’s 21-year absence from the nation’s second-largest media market.

“I often said over those 21 years what we need is a great facility,” Goodell said. “The reason the two teams left in the 1990s ... was they didn’t have an adequate stadium. I think what happened over the last years is we had two outstanding opportunities, both of these stadium projects were outstanding.”

The Chargers and Raiders can continue to negotiate with their home cities, and the league will contribute $100 million if either team builds a new stadium in their current markets.

“I will be working over the next several weeks to explore the options that we have now created for ourselves to determine the best path forward for the Chargers,” chairman Dean Spanos said.

Ray Perez, a 28-year-old Raiders fan from Sacramento who goes by the moniker Dr. Death, traveled to the Houston meeting in his usual Black Hole garb, was cautiously optimistic after hearing the news.

“I will not be completely, fully thrilled until the ink dries on paper and we know we’re staying in Oakland in a new stadium,” Perez said. “I’m very happy, very happy. But I’m not going to be overjoyed until we sign a stadium deal to keep the Raiders in Oakland with our own stadium.”

The Chargers play 120 miles south of Inglewood in Qualcomm Stadium. The Raiders played in Los Angeles from 1982-94 and currently split a facility with baseball’s Athletics, the last remaining NFL-MLB stadium.

“Relocation is a painful process. It’s painful for the fans, for the communities, for the league in general,” Goodell said. “In some ways a bittersweet moment, because we were unable to get the kind of facilities done we wanted in their markets.”

The Rams —based in the LA area from 1946-94 — will play in a temporary facility — probably the Los Angeles Coliseum — until the new stadium is ready for the 2019 season.

“Today, with the NFL returning home, Los Angeles cements itself as the epicenter of the sports world,” Los Angeles Mayor Eric Garcetti said in a statement. “We cannot wait to welcome the Rams, and perhaps others soon.”

No NFL franchise has moved since the Houston Oilers went to Tennessee in 1997. The Raiders and Rams both left Los Angeles after the 1994 season.

In a report to all 32 teams days before the meetings, Goodell deemed the venues in all three existing cities inadequate and said the stadium proposals lacked certainty.

Kroenke has said St. Louis’ economy makes it difficult for an NFL franchise to thrive there.

“We understand the emotions involved of our fans,” he said. “We made a decision and worked long and hard at the various alternatives. When they didn’t succeed, we worked this one to this point.”

The St. Louis proposal calls for an open-air, $1.1 billion stadium along the Mississippi River north of the Gateway Arch to replace the Edward Jones Dome.

The plan includes $150 million from the city, $250 million from Kroenke, at least $200 million from the league, and $160 million in fan seat licenses. The rest of the money comes from the state, either through tax credits or bonds.

Goodell says NFL policy limits the league’s contribution to $100 million, and Kroenke largely ignored the plan. The Rams have a year-to-year lease in St. Louis.

The Chargers and the city have been at odds since 2000, when owner Alex Spanos said his team needed to replace Qualcomm Stadium. That was just three years after the venue was expanded to accommodate the Chargers and Super Bowls.

The stadium saga turned nasty in the past year as Mark Fabiani, an attorney for team Chairman Dean Spanos, criticized Mayor Kevin Faulconer and his proposals. The city has claimed that the Chargers didn’t negotiate in good faith and had several misrepresentations in their relocation bid.

Spanos has had the right to leave San Diego since 2008, but the team’s efforts became more aggressive after Kroenke announced plans for the Inglewood facility. The Chargers have played in San Diego for 55 seasons after one year in Los Angeles when the former AFL franchise was born.

Oakland is still in debt from a renovation 20 years ago when the Raiders moved back from Los Angeles. City officials have said they won’t seek help from taxpayers with a new stadium, and asked the NFL for more time to develop a project in a response to the Raiders’ relocation plan.