Philip IV ruled Spain from 1605 to 1665. His favorite, the Count Duke of Olivares, constructed the Royal Palace of El Buen Retiro so that the king could relax away from ruling issues. Philip IV had two wives, Elisabeth of France who bore him two children including the future Queen of France, and Mariana of Austria who bore him Charles II, the last Habsburg king of Spain.