Blac Youngsta 's checking off a legal issue that's dogged him for years ...

a judge just dismissed his gun case in a Dallas court. The rapper was charged with unlawful possession of a firearm by a felon stemming from a 2020 arrest, but the case was was dismissed this week ..

. according to documents obtained by TMZ. BY's lawyer Carl Moore tells us his client's happy to put this case behind him after dealing with it for nearly four years .

.. saying he feels the District Attorney's Office did the right thing by dropping the charge -- and, justice has finally prevailed.

Youngsta -- who Moore tells us turned down a pre-trial diversion program before prosecutors ended up dropping the case -- was arrested in October 2020 during a routine traffic stop. He was riding shotgun in the car, and cops said they found a handgun tucked between his legs. TMZ obtained video of Blac interacting with the cops -- amiably chatting with the officers .

.. even asking how much the van they picked him up in cost.

It was Youngsta's second gun-related arrest in as many years. In September 2019, police say Youngsta claimed a bag containing 2 semi-automatic pistols in his car belonged to him, and said he had prohibited ammunition with him. We've reached out to the District Attorney's Office for more info .

.. so far no word back.

.