There is no way for you to get out of that awkward situation. The best that you can do is not give the police officer any chance to make you the bad guy.
Call the police emergency number. Give your name and address. (It's already known - caller ID blanking doesn't work when calling emergency services.) Tell the dispatcher that you believe there is an armed man in your garden shed, stealing your work tools. Don't say more than that.
Before the police arrive, somehow get rid of the gun and the police ID. Gun into the safe, and ID burnt would be good, but this probably requires a helper.
When the police arrive, say NOTHING other than: "I heard a noise, I investigated, I was terrified." Make sure nobody else says anything either.
Do NOT invite the police inside your home. Refuse permission for a search. Respond to every allegation about your conduct with, "I heard a noise, I investigated, I was terrified." Refuse to accompany the officers to the police station.
If they arrest you, vary the standard response to add, "I choose not to make a statement at this time, I want to speak to a lawyer." Don't expect that access to a lawyer will be forthcoming - what you see on TV is a) drama, and b) US-centric. In most jurisdictions you do not have "a right to an attorney".
Do NOT try and talk the officers around to your side - in all likelihood you can't.
Do NOT be nice - polite, yes, but don't do or say ANYTHING just to show that you are co-operative.
Do NOT smile because you think you are winning. Look scared (it won't be hard).
After several hours, begin asking "When may I leave?"
Eventually, you either get charged with something they make up, and front a magistrate, or they let you go.
When you get home, IMMEDIATELY call your lawyer and then lodge a written complaint about the conduct of the officer. Make sure you include that when you investigated a noise, you found him in your yard and that he then refused to identify himself. Do NOT include anything of your conduct.
Congratulations - you are now a marked man. At least one police officer has it in for you, but the others may have some doubts that you are the miscreant that he alleges you are.