Typically if there is a bounty on your head, the guards will first attempt to arrest you, rather than kill you. Are you walking around with your weapon drawn? If so, put it away. Guards will then stop attacking you and instead ask you to surrender yourself for reprimand. You will be given a choice to either pay your bounty off, go to jail to serve your time, or fight for freedom (And in some cases, if you are a Thane, you'll be able to use your clout to get out of trouble free).
If the Guards are not attempting to arrest you, but instead seem hellbent on attacking you, then something else is going on. I advise that you fast travel away from the town and wait a solid 12 in-game hours before returning. This has happened to me in Solitude before, where accidentally I interrupted the execution and was considered a threat by every single guard in the surrounding area. I fast traveled the heck out of there, waited, and when I came back everything was fine.