Copenhagen City Court also sentenced the 20-year-old man, a national of Pakistan, to deportation.
The convicted man’s identity has not been made public due to potential appeal procedures. He was born and raised in Denmark and has a two-year-old child, Ritzau reports.
The incident for which he was found guilty occurred in September 2017, when two shots were fired from a motorcycle towards two men in the back yard of a building in the Mjølnerparken housing area in Copenhagen.
The two men were police officers and were sitting in an unmarked police car.
The prosecution authority found that the shots were fired because the attacker mistakenly thought the men to be members of a rival gang named Brothas.
The case was trialled by jury, with 11 members finding in favour of a 20-year sentence and one voting for an 18-year sentence.
Monday’s sentencing follows a guilty verdict being reached in the trial on Wednesday last week, when three others were acquitted of planning to kill the two persons in Mjølnerparken.
One of the three, 20-year-old Ekram Yavuz, was, however, found guilty of possessing firearms and threatening behaviour. He was given five and a half years in prison and did not appeal the sentence.
Danish criminal law allows harsher punishments for certain crimes if they are committed in connection with gang activity.
READ ALSO: UN concerned over Denmark's plan to banish foreign convicts to deserted island