The most destructive wildfires ever to hit South Korea are almost contained, authorities say, after rain and cooler temperatures helped fire crews.