The ECOWAS court, an African regional court, has ruled that a decision by the government of Sierra Leone to ban pregnant girls from school was unlawful and must be revoked immediately.
The decision by the court for countries in the West African regional bloc has been welcomed by Amnesty International and other rights groups.
It says the ruling sent a clear message to other countries with similar bans, including Tanzania and Equatorial Guinea.
The ECOWAS court said banning pregnant girls from school was discriminatory and at odds with the African Charter on Human Rights.
The government of Sierra Leone imposed the ban four years ago when there was a spike in teenage pregnancies due to the impact of the deadly Ebola virus.
As families were torn apart many girls were left orphaned and extremely vulnerable.
The government argued that regular school would be too tiring for them and they would be a bad influence on their peers.
Alternative schools were set up for pregnant girls but rights groups argue they are not of the same standard and limit their career opportunities.