Fight a rearguard action

To try very hard to prevent something from happening when it is probably too late to prevent it.

The government is fighting a rearguard action to try and win the election.