Questions get flagged as duplicates etc, and it takes a certain amount of people to vote that question as such. But, there is no direct vote to counter the flag before it gets deleted or closed. You have to vote after the question has been dealt with. Why can't you counter a vote while it is in moderation?
You can't retract a flag ... yet.
The ability to do so has been the subject of many feature-requests on main meta for at least 5 years:
- Cancel misclicked flags
- Flag removal: Is it possible to remove your flag or otherwise indicate it should be unflagged?
- Change or reverse flag
- Can we have a way to undo a flag?
- Add ability to retract a flag
- A way to retract a comment flag?
- Can we retract active answer flags?
So far it hasn't been implemented, but the first (oldest) question linked to above has been tagged status-planned by one of the Stack Exchange Community Team, so it may be implemented in the near(ish) future.
You can, however, retract a close vote or vote to leave open.
With less than 3000 rep, you can only flag a question to recommend closure, rather than casting a fully fledged close vote. But users with over 3000 rep can retract a cast close vote by simply clicking 'close' on the question again to produce a new popup with a 'Retract Close Vote' button instead of a 'Vote to Close'.
There's also the Close Votes review queue (again, accessible only to users with over 3000 rep), where every question which has been close-voted or flagged for closure gets reviewed by the community. Each reviewer can either click "Leave Open" or "Close", and enough "Leave Open" votes will remove the question from the review queue. This is the way of "counter[ing] the flag before it gets deleted or closed" that you were looking for.