TEHRAN — Some days ago, Mahdi Taghizadeh did something he never thought he would — at least, not in Iran. He took a screen shot and shared the image with his followers on Twitter. “They were all excited,” Mr. Taghizadeh, an Internet entrepreneur, said. “Finally.”

Mr. Taghizadeh’s small triumph on the sidewalk of a Tehran street was among the first tangible results of a rare victory for Iran’s president, Hassan Rouhani, over the hard-liners who effectively rule this country. Last week, the government unexpectedly granted 3G and 4G licenses to the Islamic republic’s two principal mobile operators, which are rushing to roll out high-speed connections to their tens of millions of subscribers.

While Iranians willing to flout the law have long used illegal software to gain access to banned Internet sites like YouTube and Twitter, until now, Iran’s main cellphone operators had been ordered to reduce Internet speeds to a sub-snail’s pace, effectively making it impossible to use the sites, make video calls or send images.

Mr. Rouhani has long called for relaxing Iran’s tight grip on the Internet, but has had only limited success in the face of stern opposition from a conservative coalition of clerics, military commanders and lawmakers who have argued that any relaxation of strictures will spread immorality and unwanted ideas.