SEOUL, South Korea — A close political ally of President Moon Jae-in of South Korea was sentenced to two years in prison on Wednesday for conspiring with bloggers to illegally influence public opinion before Mr. Moon’s election in 2017.

The politician, Gov. Kim Kyoung-soo of South Gyeongsang Province in the country’s southeast, was taken to prison shortly after Seoul Central District Court convicted and sentenced him on Wednesday.

No evidence has emerged that Mr. Moon was aware of Mr. Kim’s activities. But the verdict is a political setback for the president, for whom Mr. Kim was a key adviser during the 2017 presidential campaign, in which Mr. Moon ran as a champion of clean politics.

Mr. Kim was accused of working with a blogger named Kim Dong-won, known widely by his alias, Druking, to sway online opinion in favor of Mr. Moon, both before and after the election.