We develop a general equilibrium model with search frictions in the labor market, wage bargaining and a welfare state, to study the impact of immigrants on the fiscal balance and welfare of natives in the host country. We distinguish immigrants by legal status and account for both their direct fiscal effects, through their tax contributions and transfer receipts, and their indirect fiscal and welfare effects, through their labor-market impact. We calibrate the model to the U.S. economy and find that legal immigrants reduce the tax burden on natives and increase natives' welfare, mainly because their tax contributions greatly exceed the transfers they receive. On the other hand, illegal immigrants' positive welfare impact stems mainly from their positive effect on job creation, which increases income to natives and in turn consumption. A legalization program leads to a fiscal gain, increases natives' welfare and is more beneficial to natives than a purely restrictive immigration policy that reduces the illegal immigrant population.