EDMONTON -- An Alberta man has won an appeal to serve his sentence in the community after he accidentally shot and injured his girlfriend during sex.

Matthew Bergh was sentenced to 12 months in jail for careless use of a handgun in the 2017 shooting.

In an appeal of the sentence, Bergh argued the judge overemphasized his criminal record and alcohol use.

In a ruling last week, three Appeal Court justices found the judge was wrong to conclude that a conditional sentence would be insufficient deterrence.

They also said the judge failed to consider Bergh's sincere remorse, his treatment for drug and alcohol use and that he sold all his firearms.

Court heard the shooting happened when Bergh -- unaware his handgun was loaded -- ran the barrel up and down his girlfriend's right side, back and buttocks before it accidentally fired.

The bullet entered through her abdomen and exited through her right buttock.

The woman survived, but "suffered serious internal injuries, underwent surgery and spent 18 days in hospital," the Appeal Court decision said.

Both Bergh, then 32, and his girlfriend had been consuming intoxicants throughout the night. Bergh took acid, cocaine and alcohol.

He originally told police he awoke to the sound of a single bang and thought his girlfriend had shot herself.

In Bergh's initial sentence, Judge Susan Richardson ruled that a 2010 impaired driving conviction, handling a firearm while impaired and lying to police were key reasons to not grant Bergh a conditional sentence.

The Appeal Court said Richardson placed undue emphasis on those factors.

"The sentencing judge, in our view, also failed to give due weight to the fact Mr. Bergh was a contributing member of society, an ironworker supervisor, an active and involved parent supporting a child, and that the gun was left on the bedside table because of a home invasion robbery," said the decision.

"We see no benefit in a jail sentence to deter him from committing similar offences."

Orders barring Bergh from using drugs and possessing a weapon remain in place.