Each morning, Jamal Khashoggi would check his phone to discover what fresh hell had been unleashed while he was sleeping.

He would see the work of an army of Twitter trolls, ordered to attack him and other influential Saudis who had criticized the kingdom’s leaders. He sometimes took the attacks personally, so friends made a point of calling frequently to check on his mental state.

[Update: Former Twitter employees charged with spying for Saudi Arabia.]

“The mornings were the worst for him because he would wake up to the equivalent of sustained gunfire online,” said Maggie Mitchell Salem, a friend of Mr. Khashoggi’s for more than 15 years.

Mr. Khashoggi’s online attackers were part of a broad effort dictated by Crown Prince Mohammed bin Salman and his close advisers to silence critics both inside Saudi Arabia and abroad. Hundreds of people work at a so-called troll farm in Riyadh to smother the voices of dissidents like Mr. Khashoggi. The vigorous push also appears to include the grooming — not previously reported — of a Saudi employee at Twitter whom Western intelligence officials suspected of spying on user accounts to help the Saudi leadership.