Yes, Muhammad
is indeed the last prophet, the Mahdi is just a righteous man, who happens to be a descendant of the prophet, that will appear in the future. He will be joined by Jesus and will restore justice and peace on earth and defeat all evils.
Here's a more detailed explanation about the mahdi:
"There are more than one authentic hadith indicating that the Mahdi, may Allah be pleased with him, will appear at the end of time. His appearance is one of the portents of the Last Day. Among the hadiths are the following:
1- Abu Sa'eed Al-Khudri, may Allah be pleased with him, reports that the Messenger of Allah, peace and blessings be upon him, said:
"At the end of the time of my Ummah, the Mahdi will appear. Allah will grant him rain, the earth will bring forth its fruits, he will give a lot of money, cattle will increase and the Muslim Ummah will become great. He will rule for seven or eight years."
2- `Ali, may Allah be pleased with him, says: "The Messenger of Allah, peace and blessings be upon him, said: "
The Mahdi is one of us and a member of my family. Allah will guide him in a single night." (Reported by Ahmad)
3-Abu Sa'eed Al-Khudri states that the Messenger of Allah, peace and blessings be upon, said: "
The Mahdi is of my lineage, with a high forehead and a long, thin, curved nose. He will fill the earth with fairness and justice as it was filled with oppression and injustice, and he will rule for seven years." (Reported by At-Tirmidhi)
4- Jabir, may Allah be pleased with him, says that the Messenger of Allah, peace and blessings be upon him, said: ‘‘
Jesus, son of Mary, will descend, and their leader, the Mahdi, will say, 'Come and lead us in prayer.’ But he will say, ‘No, one of them should lead them as an honor to this Ummah from Allah." (Reported by Muslim)"
source
__________________