TEHRAN, Iran—Moderate Iranian President Hassan Rouhani won re-election by a wide margin Saturday, defeating a hard-line challenger and getting an endorsement for efforts to seek better ties with the West and attract foreign investment to bolster the economy.

In his first term, Mr. Rouhani negotiated a 2015 deal with the U.S. and five other world powers to curb Iran’s nuclear program in exchange for an easing of sanctions. During the campaign he pledged to work to have remaining sanctions against Iran lifted as he fights slow...