Gambia’s President Yayha Jammeh announced that anyone marrying a girl below 18 would be jailed for up to 20 years.
In Tanzania, the high court imposed a landmark ruling outlawing marriage under the age of 18 for boys and girls.
Some 30% of underage girls are married in The Gambia, while in Tanzania the rate is 37%.
Before the Tanzania ruling, girls as young as 14 could marry with parental consent, while it was 18 for boys.
The BBC’s Tulanana Bohela in Dar es Salaam says this is a big win for child rights groups and activists, who will now have an easier time rescuing girls from child marriage.
The case was brought by lobby group Msichana Initiative.
Gambia’s President speaking at the Eid-ul-Fitr celebrations at the end of Ramadan, said parents and imams who perform the ceremonies would also face prison.
“If you want to know whether what I am saying is true or not, try it tomorrow and see,” he warned.
Women’s rights campaigners have welcomed the ban, however some say that it would be better to engage with local communities to try to change attitudes towards child marriage instead of threatening families with prison sentences,
“I don’t think locking parents up is the answer… it could lead to a major backlash and sabotage the ban,” Isatou Jeng of the women’s rights organisation Girls Agenda told the Thomson Reuters Foundation by phone from the Gambian capital, Banjul.
In December last year, Mr Jammeh also outlawed female genital mutilation (FGM), with a prison sentence of up to three years for those that ignored the ban.
He said the practice had no place in Islam or in modern society.
Three-quarters of women in the mostly Muslim country have had the procedure, according to Unicef.