A few windows were broken in the embassy, and firebombs went off outside its walls during the two-hour protest, before Iranian police wielding sticks dispersed the students.
Nearly 1,000 students gathered outside the embassy in the morning and held a peaceful protest, chanting "Death to America" and "Death to Britain" and blaming the two countries in Wednesday's bombing of the shrine in the Iraqi town of Samarra.
"We hold the occupiers of Iraq responsible," one banner read. They also held signs denouncing caricatures of the Prophet Muhammad that were printed in European papers.
The larger demonstration ended without incident. But several hours later, around 400 students returned and attacked the embassy.
The Iraqi government has accused Sunni militants in the attack, which destroyed the shrine's golden dome and sparked a bloody wave of sectarian violence between Iraq's Shiites and Sunnis that security forces are still struggling to contain.
But some Shiites across the Mideast have directed their anger at the U.S. military presence in Iraq, saying they failed to provide security. Britain has troops in the U.S.-led multinational force in Iraq.
On Thursday, the president of Iran — a predominantly Shiite nation — accused the United States and Israel of carrying out the bombing to divide Muslims.