Did you sign any contract with the first company? If not there's nothing to do except apologize for having to rescind the offer and wish them the best.
> I am not sure how to go about backing out of the one that I accepted already.
Almost the same way as you said in this post. Don't mention the panic, do mention that the other offer is personally very interesting to you.
Do this after you have accepted and confirmed the second offer. The earlier you do this the better.
There is of course value in keeping your word once you have accepted something - but for how long would you work at a less interesting position for just that? A few months, a year, 3-5 years? If under a few years, then you aren't actually helping them by accepting and "keeping your word".
Just be honest and respectful. Preferably over the phone/audio/video rather than an email. Also, be clear and to the point, so they know you're not just trying to get more money out of them.
(If it's just about the money and they offer, it's a different dilemma).
If you haven't signed anything you are under no obligation, if it was in the company's best interest not to refuse you after accepting you they would in a minute. say politely you've changed your mind, at the worst they will offer you some more money.
As others have said, if you don't have a contract, you can legally walk away.
Legally.
But there might be another question. To what degree do you consider that you gave your word? And how much is your word worth to you? If you're a "my word is good" kind of person, then "legally" isn't the only consideration. You might see if you can get the company (or your friend) to release you from your acceptance, to whatever degree you feel is needed.
I wonder if you live in an at-will employment state (e.g. California), does it even matter if you signed something?
Honesty is the best policy here:
"When I was interviewing for the job with you, I was also interviewing with other companies. Your offer came in first and the job sounded interesting and the pay was good so I accepted. However, since then one of the other companies I interviewed with has given me an offer for a more interesting/better paying/shorter commute/etc. job and so I've decided to accept that offer. I hope this doesn't negatively impact you and that you can quickly find someone else."
Or something like that. Tells them the honest reason why, doesn't burn your bridge too badly.