The Economic Community of West African States (ECOWAS) court issued its ruling following a suit brought by a Nigerian NGO called the Socio-Economic Rights and Accountability Project (SERAP) and rights campaigners.
In a summing-up statement sent to AFP the court stated the ban, which received international criticism, was illegal, violated people's freedom of expression and access to the media, and went against the International Covenant on Civil and Political Rights as well as African Charter rules.
In declaring the ban unlawful the court also ordered the Nigerian authorities never to repeat it.
The Abuja government suspended Twitter in June last year after the social media giant deleted a tweet by President Muhammadu Buhari. It lifted the ban in January after talks with Twitter representatives but laid down conditions, including Twitter registering its operations in Nigeria.
With three-quarters of Nigeria's population of 200 million aged under 24 the country is hyper-connected to social media. Around 40 million Nigerians, or around 20 percent of the population, have a Twitter account.
The ban shocked many in Nigeria, given Twitter's major role in political discourse, as evidenced by the #BringBackOurGirls hashtag deployed after Boko Haram extremists kidnapped nearly 300 schoolgirls in 2014.
Young activists also turned to Twitter to organize the #EndSARS protests against police brutality that eventually grew into the largest demonstrations in Nigeria's modern history before they were repressed.
Abuja initially announced an unlimited ban, accusing the platform of allowing activities it said threatened the country's existence citing posts by separatist agitators from the country's southeast, where a civil war five decades ago killed one million people.
Nigeria's National Information Technology Development Agency (NITDA) director general Kashifu Inuwa Abdullahi at the time said there were "unscrupulous elements" using Twitter "for subversive purposes and criminal activities, propagating fake news, and polarizing Nigerians."