PEZINOK, Slovakia — Zuzana Caputova had been battling to close a toxic landfill in her hometown, Pezinok, in Slovakia for years when she learned that the wife of her closest colleague had been stricken with an aggressive form of cancer. That same week, her godfather was told that he, too, had cancer.

“Part of my personal motivation to get involved in this case is that I was scared of cancer,” she said. “And suddenly, in this week, the first week of June 2006, these two roles — the personal and professional — came together.”

That experience convinced Ms. Caputova that what counted most was doing her best to win the case and not to worry about the result, which she could not control. She did eventually win it before the European Court of Justice in 2013, and says she now plans to bring that same attitude to her new job.

On Saturday, Ms. Caputova, a 45-year-old lawyer and political neophyte who has never held state office, became the first woman sworn in as president of Slovakia.