I recently applied for a US visa and had the interview, where I was told the application wasn't approved pending a medical examination. I have since found out that I could have travelled on an ESTA after all, so tried to withdraw the visa application. However, I have now had an email back from the embassy saying they will hold my visa application 'pending' for 12 months in case I change my mind and decide to go ahead with it (so that I don't have to pay again). The ESTA application asks if I have ever been denied a visa. Can I say no to this, as I wasn't actually denied a visa, it just wasn't approved until my medical examination was completed, and I subsequently withdrew? Does this mean I now cannot apply for an ESTA for those 12 months while I still have a visa pending?
You were never denied a visa, so the answer is no. Just answer every question factually and truthfully and, if you ever have to, be prepared to explain the situation.
Note however that a B1/B2 visa, which is presumably what you applied for, is "stronger" than an ESTA on numerous aspects, so if you went this far anyway and if you think you may benefit from it at some point, you may want to finish off the process. Of course there is no guarantee on how long the visa will be valid for.
If no action was taken on your visa and it remains pending, then it has not been refused. After all, the embassy themselves state that you can resume the application!
'pending' means "awaiting decision or settlement". So if you were told it was "pending a medical examination", that would mean immigration department would make their decision when they receive the medical reports. At this time, it's just an application, and a decision has not been made.
A refusal or grant would mean a decision HAS been made.
Even if you withdraw the application, that would still mean an application was received, and subsequently withdrawn; a decision had not been made. Hence, you would NOT have been denied a visa by immigration department.
Instead of withdrawing your application, you may allow them to withhold your application, in case you change your mind within 12 months. After that, you may submit another application, with another fee.
For your ESTA application, you'd say "NO" (since you've NOT been denied a visa, on this occasion). You'd, of course say "YES" if you HAVE been denied a visa on any previous occasion to this. If the ESTA application has a question: if you have another visa application pending, you'd say "YES".
If you need the money back, you may ask immigration if you get a refund BEFORE you go ahead and withdraw the application.