Lyles turned up the positive test on Tuesday, officials said - two days after he won the 100 metres - and appeared to be in physical distress after Thursday's final in the longer sprint.
"I believe this will be the end of my 2024 Olympics. It is not the Olympics I dreamed of but it has left me with so much joy in my heart," he wrote on Instagram.
Lyles leaves an Olympic champion but the abrupt end to his campaign was almost certainly a bitter pill to swallow, as he had set the ambitious goal of winning four golds in Paris, in the 100m, 200m, 4x100m relay and the 4x400m relay.
It also marked the triple 200 world champion's first defeat in a 200m final for three years.
The star of the Netflix docuseries SPRINT congratulated gold medallist Letsile Tebogo of Botswana and compatriot Kenny Bednarek, who finished second in the 200, and thanked his fans for the messages of support.
"I hope everyone enjoyed the show," Lyles wrote.
"Whether you were rooting for me or against me, you have to admit you watched, didn't you?"