Headmaster Dippet and possibly the Head of Gryffindor - the Headmaster can expel Hogwarts students, and the Ministry can’t.
Hagrid would have been expelled by Dippet, the Headmaster of Hogwarts at the time he attended, since the headmaster is the one who has the power to expel students. The Tom Riddle in the diary tells Harry that it was his word against Hagrid and he would have seemed clearly more credible to Armando Dippet.
“Riddle laughed his high laugh again.
‘It was my word against Hagrid’s, Harry. Well, you can imagine how it looked to old Armando Dippet. On the one hand, Tom Riddle, poor but brilliant, parentless but so brave, school Prefect, model student; on the other hand, big, blundering Hagrid, in trouble every other week, trying to raise werewolf cubs under his bed, sneaking off to the Forbidden Forest to wrestle trolls. But I admit, even I was surprised how well the plan worked.”
- Harry Potter and the Chamber of Secrets, Chapter 17 (The Heir of Slytherin)
Dippet, as headmaster, would have made the final decision to expel Hagrid. Hagrid’s Head of House, whoever was the Head of Gryffindor then, also may have had a say in the decision, as when Harry and Ron fly a car to Hogwarts, Snape goes to get the people who can expel them, and returns with McGonagall and Dumbledore.
“‘Silence!’ snapped Snape again. ‘Most unfortunately, you are not in my house and the decision to expel you does not rest with me. I shall go and fetch the people who do have that happy power. You will wait here.”
- Harry Potter and the Chamber of Secrets, Chapter 5 (The Whomping Willow)
The headmaster likely makes the final decision, as in that same incident, Dumbledore warns Harry and Ron that if they do anything like it again, he will have to expel them.
“What are you talking about, Weasley?’ barked Professor McGonagall.
Well, you’re expelling us, aren’t you?’ said Ron.
Harry looked quickly at Dumbledore.
‘Not today, Mr Weasley,’ said Dumbledore. ‘But I must impress upon both of you the seriousness of what you have done. I will be writing to both your families tonight. I must also warn you that if you do anything like this again, I will have no choice but to expel you.”
- Harry Potter and the Chamber of Secrets, Chapter 5 (The Whomping Willow)
As Dumbledore reminded its officials when they tried to expel Harry, the Ministry does not have the power to expel Hogwarts students. It does have the power to confiscate wands, but only after charges have been successfully proven.
‘The Ministry does not have the power to expel Hogwarts students, Cornelius, as I reminded you on the night of the second of August,’ said Dumbledore. ‘Nor does it have the right to confiscate wands until charges have been successfully proven; again, as I reminded you on the night of the second of August. In your admirable haste to ensure that the law is upheld, you appear, inadvertently I am sure, to have overlooked a few laws yourself.”
- Harry Potter and the Order of the Phoenix, Chapter 8 (The Hearing)
Therefore, the Ministry could not have expelled Hagrid because it would not have had the authority to expel Hagrid from Hogwarts.