This paper develops an analytical framework for assessing the second-best optimal level of gasoline taxation taking into account unpriced pollution, congestion, and accident externalities, and interactions with the broader fiscal system. We provide calculations of the optimal taxes for the US and the UK under a wide variety of parameter scenarios, with the gasoline tax substituting for a distorting tax on labor income. Under our central parameter values, the second-best optimal gasoline tax is $1.01/gal for the US and $1.34/gal for the UK. These values are moderately sensitive to alternative parameter assumptions. The congestion externality is the largest component in both nations, and the higher optimal tax for the UK is due mainly to a higher assumed value for marginal congestion cost. Revenue-raising needs, incorporated in a "Ramsey" component, also play a significant role, as do accident externalities and local air pollution. The current gasoline tax in the UK ($2.80/gal) is more than twice this estimated optimal level. Potential welfare gains from reducing it are estimated at nearly one-fourth the production cost of gasoline used in the UK. Even larger gains in the UK can be achieved by switching to a tax on vehicle miles with equal revenue yield. For the US, the welfare gains from optimizing the gasoline tax are smaller, but those from switching to an optimal tax on vehicle miles are very large.