Sounds like you're using Upwork? If not, let me know and I'll adjust this.
Personally, I've been using Upwork for over a year and pretty much stopped using it because of low-quality clients.
If there was no issue with your work during the development process and the client was able to see your work and then all of a sudden is not happy, that's a little suspicious. Unless, they're not satisfied with what's happened since the most recent billing period.
This client may be happy but may want to keep the work and make back the payment so, in essence, you worked for free.
Nevertheless
You are paid for your time especially during hourly contracts. You're paid $x/hour for your expertise and skill. You provided a service, even if it wasn't completely up to the clients expectations - you put in the time and your time is worth something.
I've been threatened a lawsuit or two in my time and have always been able to resolve the situation but I am not promising that your situation won't escalate.
Ask the client for specifics as to why they're not happy, why they didn't bring up issues earlier, etc. This can all be used to call BS or as evidence later on.
- Inform support. This client may have done this before/ have a history of threatening a lawsuit
- Offer x amount of hours of free work to fix major issues
- Offer to work at a discount (I'd say at least 50%) to fix issues
If they don't want you to fix anything then remove your work. I would tell them that I'm sorry they're unhappy with my work and that I'll refund them x% (I did this once and gave back 50%) but that I will be removing my work as they're not happy with it and I don't want to leave them with low-quality work or with work that was done but not technically paid for (because of the refund).
Here's the thing about legal action - no one is safe.
I could sue you because you missed a comma in your question or claim you keyed my car. I could bring it to court as well (more than likely would be thrown out). Anyone can sue anyone for anything. If things do escalate then you need to be prepared to build a case. Save all work hours, save all communications through all methods, have proof of work, etc.
STAY PROFESSIONAL
Through ALL communication stay professional, helpful, calm, and don't use profanity.
If none of this works and they decide to proceed with a lawsuit
Let the client know you're prepared to defend yourself.
This had a client back off of a lawsuit from me once:
I have X which proves you had no problem with the work after seeing it multiple times.
Y shows communication between us that I offered to fix the problem but you wanted to keep my work and get a full refund.
I'm not a lawyer but you may want to research one.