In a landmark decision, the court ordered monitoring stations and other measures to improve the capital's air.
The lawsuit was filed by residents in 2019 and the verdict has since been postponed several times.
Air pollution is reducing Jakarta residents' life expectancy by 5.5 years, US researchers say.
Persistent smog in the city of 10 million people is caused by heavy traffic and coal-fired power plants that have not been fitted with filters.
The district court has instructed Mr Widodo to improve the national standard of air quality, adding that the provincial government must conduct checks such as periodical emission tests for older vehicles in Jakarta and outdoor air quality tests.
This information must be made public, the court said.
Frustrated residents worried about the impact on health launched the legal action against President Widodo, the environment ministry, Jakarta's governor and others.
One of the plaintiffs, researcher Khalisah Khalid, said she had participated because her 10-year-old son suffered frequent nosebleeds as well as allergies.
"This is the background. I want my child to be able to live a healthier life, get clean and healthy air," she told BBC Indonesian.
"I'm sure all parents, all mothers, want their children to be able to grow and develop... in a clean and healthy environment."
Another plaintiff said the court ruling was a good start.
"The government breathes the very same air so we hope they are now aware of it and make progressive measures to make our air cleaner," said Veronica, who like many Indonesians goes by one name.
Jakarta's particulate pollution levels are six times the World Health Organization's guideline level, according to the University of Chicago's Air Quality Life Index.
Meanwhile President Widodo is pressing ahead with plans to move Indonesia's capital out of Jakarta to East Kalimantan on the island of Borneo, nearly 1,300km (800 miles) away.
On Wednesday local media quoted him as saying that officials would benefit from the fresh air and the green environment there. Ministers currently need police escorts to get through Jakarta's notorious traffic and reach meetings on time.
Some basic facilities in the new capital could be operational by 2024, Mr Widodo added, but officials say it will take up to 20 years to finish the project.