Moses has flaws but was still a humble great leader. When it was time to end his leadership he cried out to God and God already had a plan.
12 One day the Lord said to Moses, “Climb one of the mountains east of the river, and look out over the land I have given the people of Israel. 13 After you have seen it, you will die like your brother, Aaron, 14 for you both rebelled against my instructions in the wilderness of Zin. When the people of Israel rebelled, you failed to demonstrate my holiness to them at the waters.” (These are the waters of Meribah at Kadesh in the wilderness of Zin.)
15 Then Moses said to the Lord, 16 “O Lord, you are the God who gives breath to all creatures. Please appoint a new man as leader for the community. 17 Give them someone who will guide them wherever they go and will lead them into battle, so the community of the Lord will not be like sheep without a shepherd.”
18 The Lord replied, “Take Joshua son of Nun, who has the Spirit in him, and lay your hands on him. 19 Present him to Eleazar the priest before the whole community, and publicly commission him to lead the people. 20 Transfer some of your authority to him so the whole community of Israel will obey him. 21 When direction from the Lord is needed, Joshua will stand before Eleazar the priest, who will use the Urim—one of the sacred lots cast before the Lord—to determine his will. This is how Joshua and the rest of the community of Israel will determine everything they should do.”
22 So Moses did as the Lord commanded. He presented Joshua to Eleazar the priest and the whole community. 23 Moses laid his hands on him and commissioned him to lead the people, just as the Lord had commanded through Moses.