Camille Pissarro's Rue Saint-Honoré in the Afternoon. Effects of Rain has been in the museum's collection since 1993
Madrid's Thyssen-Bornemisza Museum has fought a 14-year legal battle in the US with the family of Lilly Cassirer.
Ms Cassirer was forced to trade the valuable Camille Pissarro painting for her freedom as she tried to flee Germany, just before the war.
A federal judge in California ruled that legally it belongs to the museum, which acquired it in 1993.
According to Spanish law, if a collector or museum does not know that an artwork was looted when they acquire it, then they are legally entitled to keep it.
But the judge, John Walter, criticised Spain for not keeping to the Washington Principles on Nazi-Confiscated Art - an international agreement to return Nazi-looted art to the descendants of the people they were taken from.
Some 44 nations, including Spain, signed it in 1998.
In his written decision, Judge Walter said that despite being legally entitled to keep the artwork, Spain's insistence on keeping the painting - Pissarro's Rue Saint-Honoré in the Afternoon. Effects of Rain - was "inconsistent" with the agreement.
Washington Principles, he said, was "based upon the moral principle that art and cultural property confiscated by the Nazis from Holocaust victims should be returned to them or their heirs".
He also said that Baron Hans-Heinrich Thyssen-Bornemisza, the German industrialist who bought the painting from a US dealer in 1976, should have been aware of the "sufficient circumstances or 'red flags'" that signalled it had been looted - such as missing and damaged provenance labels.
His decision leaves open the possibility of appeal - although the Cassirer family has yet to say whether they plan to do so.
The lawyer acting for the museum, Thaddeus Stauber, told the Associated Press news agency that that the verdict "puts an end to" the dispute.
However, the Cassirer family's lawyer Steve Zack told AP: "We respectfully disagree that the court cannot force the kingdom of Spain to comply with its moral commitments."
Ms Cassirer's father-in-law bought the painting from Pissarro's art dealer in 1900. Her grandson, Claude Cassirer, told the LA Times in 2010 that he had vivid memories of seeing the Pissarro painting hanging on her wall while growing up in Berlin in the 1920s.
In 1939, months before the start of World War Two, Ms Cassirer tried to escape the country. However, a Nazi official forced her to hand over the painting in exchange for the exit visa.
After the war she, along with other European Jews, sought help from the Allied forces in being reunited with looted art. In 1999 a friend of Claude's discovered that it was on display in the Thyssen-Bornemisza Museum.
Claude filed the lawsuit in 2005 but died in 2010. His son David now deals with the case.
Baron Thyssen-Bornemisza's entire art collection was bought in 1993 and turned into a museum bearing his name.