Find a way for Spain to beat the US which would include retaining all/some of its colonies.
The Spanish should sell or give the territory of the Tagalog Republic(Luzon) to somebody else (the British) before the war instead of trying to make peace with them via Aguinaldo, but in reality they should had lost that territory in the 7 years war to Britain with the compensation of Maluku, since the natives of Maluku prefer the Spanish more than the people of Luzon.
I think that would be a better scenario for the Spanish.
The only people who would want Luzon are the British, not the Germans since it is the land that they were supposed to get in the 7 years war and they have businesses connected to Britain there as well wherein they can start to consolidate their rule(which is basically also connected to Americans as well) which would smoothen the process, the Americans and Germans have similar interests and would want to control the south of the archipelago.A 7 years PoD has too many butterflies which may avoid the Spanish-American War. OP states he wants Spain to win, not necessarily avoid it.
Selling it to the British or Germans seems also doable in the late 19th century right?