What was taken out of schools first, the Pledge of Allegiance or prayer?
State-sponsored prayers in public schools were banned by the Supreme Court of the United States in 1962. This was done in the case of Engel v. Vitale. Students are, of course, free to pray silently whenever they wish. Therefore, it is not really accurate to say that prayer has been taken out of schools.
The Pledge of Allegiance has not been taken out of schools in any way. It remains legal to have a school-mandated recitation of the Pledge of Allegiance. The only limitation on this is that students may not be required to recite the Pledge.
So, of these two, school-sponsored prayer has been banned, but the Pledge of Allegiance has not.
School-led prayer was deemed unconstitutional in 1962, but school-led recitation of the Pledge of Allegiance was never deemed unconstitutional.
The Supreme Court decided in Engel v. Vitale that it violated the First Amendment's Establishment Clause for teachers and administrators to encourage students to recite a non-denominational prayer at the beginning of the school day. The prayer in discussion referred to Christian beliefs, which made it seem like the public and government-funded school was endorsing Christianity.
“Almighty God, we acknowledge our dependence upon Thee, and we beg Thy blessings upon us, our parents, our teachers, and our country.”
Schools can hold "moments of silence" where students may choose to pray – the simply can't suggest that students should pray during that time.
While the Pledge of Allegiance has been the subject of many First Amendment cases, especially focused on the words "under God," schools are still allowed to say "please stand for the Pledge of Allegiance" and encourage students to say the pledge. Schools cannot punish students for not actually saying the words as decided by the Supreme Court in West Virginia State Board of Education v. Barnette (1943).
In Elk Grove United School District v. Newdow (2004) the school district appealed a previous decision agreeing that it was unconstitutional for Newdow's daughter to be forced to hear the recitation including "under God," regardless of if she required to say it. The Supreme Court's majority decided that Newdow didn't have the proper standing to sue because he didn't actually have custody of the daughter in question, but three concurring opinions stated that if he did have standing, those justices would've ruled in favor of the school district.
Therefore, the Pledge of Allegiance still stands in schools.