WASHINGTON—The U.S. government is posting the strongest revenue since before the recession, buoyed by higher tax rates and a slowly improving economy, leaving the federal budget on track for its narrowest deficit in five years.

Revenue from October to July, the first 10 months of the government's fiscal year, totaled $2.287 trillion, the Treasury Department said Monday. That is up about 14% from a year earlier and about 8.1% from the first 10 months of 2007, the next highest year for revenue. Meanwhile, government spending...