An American missionary held captive in North Korea for two years credited eccentric hoopster Dennis Rodman for his release — even though the ex-NBA star initially spoke out in defense of the oppressive hermit kingdom.

A forgiving Kenneth Bae said Rodman inadvertently played a key role in getting him out of North Korea in November 2014.

Two years ago, Rodman visited his pal North Korean dictator Kim Jong Un, and went on a rant afterwards, all but saying Bae deserved to be locked up.

“If you understand what Kenneth Bae did,” Rodman yelled on CNN. “Do you understand what he did in this country? Why is he held captive in this country?”

For that rant, Bae said on Monday: “Thank you.”

“I want to thank Dennis Rodman for being a catalyst for my release,” Bae told CNN’s “New Day.”

“Because of his rant, the media attention on my plight was increased. So if I meet him someday, I will just want to say `thank you’ for what he has done that really brought international attention to my plight.”

Bae added: “Altogether it worked out for good for my release. I’m grateful.”

Bae had been sentenced to 15 years of hard labor in North Korea for bringing Christian material to the country.

Rodman has since apologized to Bae’s family for his kooky defense of Kim.

“He did apologize to our family afterwards … a sincere apology,” said Bae, who penned a book, “Not Forgotten,” about his time in North Korean captivity.