Spain’s Socialist government had a pretty good argument to make to the electorate: unemployment was low; the economy was growing; and issues with the Basque and Catalonian nationalists were under better control. Nevertheless, the polls indicated that the government was going to lose badly. A right-wing government was a virtual certainty.
Sanchez made the election a referendum on right-wing extremism. It paid off; in spite of his low popularity ratings in the polls, the voters basically supported the status quo.
Does this bode well for Biden, who figures to run a similar campaign under similar circumstances? You bet it does.