In my heroic and celebrated sex life this has happened to me twice. Yes, both times were humiliating - to me, to the girl and to my dear penis.
But both times were because I was trying to will myself to get sexy with someone I probably shouldn't have been with in the first place. No, not because it was a farm animal or my best friend's wife, but simply because I wasn't all that attracted to her, didn't click with her on any emotional basis and was just trying to get laid for lay-sake.
Here's the deal: The penis is like George Washington. It cannot tell a lie.
If it's really not feeling it - it will let you know. Usually by shriveling up or just playing dumb. The more you try to force it on him, the more likely he will retreat and get pissed. "Screw you, Owner!" Your dick will say. "Go down on her or something, cuz I ain't touching her with a ten foot pole."
To put it another way, your penis is like your emotional thermometer. It gauges how hot or not you are for someone at the moment and rises accordingly. I wouldn't beat yourself or him up about this. Rather try to find a partner that feels more right. I'm not saying leave everything up to your dick and take a back seat, but find someone that satisfies and engages you on more levels - physical, emotional, personality, etc.
As for mending things with your female buddy, it might take some time, but slowly work towards meeting back in the friend-zone. You don't have to tell her point blank why it didn't click - A. she can probably figure it out and B. if you guys were really tight she'll soon be able to not take it so personally. She will hopefully laugh about it and chalk it up to a "Hey, we tried. That was a hot mess. Now let's grab a beer you Little Bastard."