Quadrupling the current maximum six-month term showed his determination to "take a stand against a baying cyber-mob".
BBC News - Internet trolls face up to two years in jail under new laws
Mr Grayling was speaking days after TV presenter Chloe Madeley suffered online abuse, which Mr Grayling described as "crude and degrading".
She has welcomed the proposed laws but said social media should be regulated.