In September 1984, Nigerian music legend Fela Kuti found himself in a familiar position: under arrest.

Sent to England to study medicine decades before, Kuti had instead invented Afrobeat, an infectious version of James Brown’s funk gone global. Radicalized in the United States by his contact with the Black Panthers, Kuti became more than a pop star, but a political force in Nigeria — a marijuana enthusiast, polygamist and sometime presidential candidate who became “the voice of Nigeria’s have-nots, a cultural rebel,” as AllMusic put it.

“In the last military regime I was the only one to speak out against the government and the army,” he said in 1978. “Anything could happen in Nigeria. If they get to the point that everyone trying to rule the place isn’t making any headway they might drop their guard and ask, ‘Fela, do you want to rule us today?’ ”

Continually running afoul of his country’s powers-that-be, Kuti was repeatedly detained. In 1977, government forces even raided his compound — which the singer had declared independent of Nigeria — with a 1,000-man force, resulting in the death of his mother. And the singer was on his way to the United States seven years later for a tour when he was arrested for what the Guardian called “sham currency smuggling charges.”

Nigeria’s leader at the time: Muhammadu Buhari, who the country just put back in power. Buhari was elected this week in what The Washington Post’s Karen Attiah calleda largely peaceful and credible election, with its most transparent vote to date.”

Elected amid his nation’s ongoing war against the terrorist group Boko Haram, Buhari doesn’t just have radical Islamists to worry about. Though he proved victorious in a free and fair vote, Nigeria’s new leader also has his dictatorial past to overcome. After all, this is the man who engineered a coup in 1983 and put himself in charge of Africa’s most populous country.

“A lot of people will tell you that they have their reservations about Buhari for many reasons — some because he was a military dictator and they worry whether he can uphold democratic principles and create democratic space,” Kadaria Ahmed, a Nigerian journalist and political analyst, told the Associated Press.

When it came to Fela Kuti, democratic principles didn’t seem get in Buhari’s way 30 years ago. Buhari’s government was behind Kuti’s arrest, and the singer was quickly sentenced to five years amid allegations reported by Amnesty International that witnesses were prevented from testifying on his behalf. There were even reports that the judge who sentenced Kuti later apologized to him.

“He went and declared to Fela that, ‘Man, you were not guilty, I was under pressure, I was instructed to put you behind bars,’ ” Rilwan “Showboy” Fagbemi, Kuti’s former saxophonist, claimed in 2012. “‘And as a judge, if I don’t tell you the truth, I will never forgive myself. I came for your forgiveness, forgive me. You did not commit any offense. You were jailed because I had the order to put you behind bars from above.'”

Buhari’s chief of staff was unmoved. “I hope he will rot in jail,” he said.

But that was not Kuti’s destiny. After Buhari was unseated — by another coup — in 1985, the singer was released. He lived to take musical revenge on Buhari — name-checked in Kuti’s less-than-complimentary song “Beasts of No Nation,” reportedly the first song he wrote after he got out of prison. Here it is:

Kuti died of complications from AIDS in 1997 — and, of course, has been lionized in a smash Broadway musical, “Fela!” But now, Buhari is back. And though he may prove more effective against Boko Haram than his predecessor, Goodluck Jonathan, some Nigerians are wary.

“To deceive Nigerians that Buhari is capable of taming Boko Haram, his supporters have been distorting history,” Sani Tureta of the Nigerian newspaper This Day wrote in January of this year, citing Kuti’s detention. “… Buhari truncated the process of justice and perpetuated the denial of individual liberty – two issues that are bedrocks of democracy.”

As The Post’s Kevin Seiff wrote: “Nigeria has evolved since Buhari’s regime, and it appears he has, too. Buhari has traded his pressed green military uniform for a traditional flowing robe. In a speech in London last month, he described himself as ‘a converted democrat who is ready to operate under democratic norms.’”

One wonders what Kuti would think of Buhari’s revival.

“This was the mouthpiece of the poor masses of this country,” saxophonist Fagbemi said. “This was the only man that [said] …’Why are my people deserve this? Why are you giving them this?’ ”